惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
爱范儿
爱范儿
Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss
B
Blog RSS Feed
博客园 - 聂微东
G
GRAHAM CLULEY
Engineering at Meta
Engineering at Meta
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
WordPress大学
WordPress大学
Scott Helme
Scott Helme
AI
AI
S
Security Affairs
T
Threat Research - Cisco Blogs
M
MIT News - Artificial intelligence
T
Troy Hunt's Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
人人都是产品经理
人人都是产品经理
AWS News Blog
AWS News Blog
T
Threatpost
Cyberwarzone
Cyberwarzone
www.infosecurity-magazine.com
www.infosecurity-magazine.com
U
Unit 42
V
Vulnerabilities – Threatpost
J
Java Code Geeks
博客园 - Franky
月光博客
月光博客
Blog — PlanetScale
Blog — PlanetScale
NISL@THU
NISL@THU
D
Docker
小众软件
小众软件
N
News and Events Feed by Topic
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
A
Arctic Wolf
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
Forbes - Security
Forbes - Security
量子位
PCI Perspectives
PCI Perspectives
美团技术团队
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
有赞技术团队
有赞技术团队
腾讯CDC
P
Proofpoint News Feed
S
Security @ Cisco Blogs
G
Google Developers Blog
C
Cisco Blogs

Sehnsucht

记一次博客换图床的过程 观《花束般的恋爱》 读《活过》 东京 旅行篇 亲人逝去 我为什么想养鱼 防止AI爬取你的博客 「monthly 」博客重构 游戏全成就 好看的小说 人生的每一步都不会是浪费-2024年终 「weekly」星期五综合征 「weekly」听播客 杂谈 读《美丽新世界》 「weekly」社交媒体 恶性事件 新世界 「weekly」认知觉醒 美丽新世界 follow 「weekly」独立博客9问题 双十一买书 读《惊呆了!原来这就是社会学》 一次聊天与自我建设 2024-09月记 补番《relife》 树状数组简单理解 lvm简单使用 博客自动发布方案 某公众号废案 fail2ban基本使用 Podman 环境使用 Nginx Proxy Manager 最佳实践 2024-07同学聚会 vps使用podman部署freshrss Gitlab CICD 实践,思考与记录 装备升级:新的PC gitlab局域网搭建流程 FastMail迁移至GMail+Cloudflare Email Routing 读《黑客与画家》 leetcode 第 391 场周赛 Astro添加过渡后DarkModeToggle按钮失效 nuxt3使用echarts5渲染中国地图 人生刻度 又到凤凰花朵开放的时候 2023-05-10 实习结束 2023-04-26 广州博物馆游记 YOASOBI「たぶん」官方音乐视频 风灵玉秀-发如雪 带我的老哥离职了 从p10k转向Starship lunarvim国内安装踩坑记录 什么是对称加密非对称加密、密钥交换、数字签名、证书 强调体验的一种思考时间的方式 ArchLinux使用vscode编写latex报错The font "FontAwesome" cannot be found ArchLinux安装(移动硬盘)流程 yay一个或多个文件没有通过有效性检查! 2022年终 hugo建站伊始 clash设置relay前置代理(校园网破解改进记录) 群青 · YOASOBI · Ayase 华为 matepad pro 11使用体验 Nginx使用acme.sh免费安装ssl证书 永远属于你的安娜 在线 童年趣事 童心,是比野心更难得的梦想 2021年终总结 基于jeeSite的软件测试课程作业 流程记录 Linux不同用户安装不同版本jdk Wifi4更换Wifi6路由器的使用体验 Flask 上传图片并灰度显示 玩客云刷机debain个人记录 jython 简单入门 Jenkins 个人搭建流程记录 集成邮件系统(qq邮箱),gitlab服务器,freestyle风格 在Web项目中配置Log4j --指南-- Codeforces Round 753 (Div. 3) ABCDE 浅谈fork函数 JavaWeb servlet 使用Cookie记录用户访问次数 Codeforces Round Educational Codeforces Round 114 (Rated for Div. 2) ABC 2021牛客多校7 I xay loves or 2021牛客多校9 H Happy Number 2021牛客多校8 D OR 2021牛客多校5 B Boxes 2021牛客多校5 H Holding Two 2021牛客多校2 D Er Ba Game 2021牛客多校1 F Find 3-friendly Integers 2021牛客多校1 B Ball Dropping 记人生第一次投简历和笔试 原型模式 2021-2-20 雨时随记 关于一维差分数组的例子 halo个人建站 关于手机ping电脑和电脑ping手机 泛型类简单理解 CodeForces - 849C From Y to Y 2020牛客国庆集训派对day3 Leftbest mysql 5.7 忘记密码如何更改 CF 1099B Squares and Segments CF 998A Balloons CF 998B Cutting 链表应用之多项式相加 CF 1150A Stock Arbitraging CF 1199A City Day CF 1199B Water Lily CF 982A Row CF 934A A Compatible Pair CF 629B Far Relative’s Problem 651A Joysticks 651B Beautiful Paintings
约瑟夫环问题---2020牛客国庆集训派对day2 AKU NEGARAKU
2020-10-03 · via Sehnsucht

题面

链接:https://ac.nowcoder.com/acm/contest/7818/A 来源:牛客网

时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 1st Academy is an international leadership training academy based in Kuala Lumpur. Every year, the company trains thousands of people to be supplied to companies around the world. To be fair amongst all the trainees, the company will do the selection process using numbering system. The trainees will choose a number from 1 to N, and one number is not limited to only one trainee. The N represents the total number of companies that request trainees from the academy. A number, M, would be picked at random, and the selection starts with a trainee whose number is 1, and then in every M’th people after that, wrapping around to 1 after N, and ignoring trainees already selected. For example, if N = 15 and M = 6, trainees would be selected in the order: 6, 12, 3, 10, 2, 11, 5, 15, 13, 9, 14, 4, 1, 8, 7. All the selected trainees except the last one (which is number 7) will be supplied to companies outside of Malaysia. However, Leong preferred to stay and work in Malaysia. To him, there is no better place other than Malaysia. He does not mind being located anywhere as long it is Malaysia. As a friend of him, you could help him to choose a number that will save him from being located outside. Input 输入描述: Input will consist of a series of lines, each line containing the number of companies (N) with 1 \leq N \leq 15001≤N≤1500, and a skipping value (M) with 1 \leq M \leq 501≤M≤50. The values will be terminated by a line consisting of double zeros (0 0) as shown in sample input output. 输出描述: Output will consist of a series of lines, one for each line of the input. Each line will consist of the number M according to the above scheme. 示例1 输入 复制 15 6 550 23 0 0 输出 复制 7 470

我写的代码

#include<bits/stdc++.h>
using namespace std;
int cb[10000];
int main()
{
	int n,m;
	while(~scanf("%d %d",&n,&m))
	{
		int ans = 0;
		memset(cb,0,sizeof(cb));
		int cut = 0;
		if(n == m && n == 0)break;
		for(int i=1,j=1,k=0,l=0; k!=1000000 ; i++,j++,k++){
//		k总计数,i下标,j看是否为m整除,l统计已被记录的数量 
			if(i == n+1)i = 1;
			if(cb[i] == 1){//被标记则跳过 
				j--;
				continue;
			}
			if(j % m == 0){
				l++;
				if(l==n){
					ans = i;
				}
//				printf(" *%d* ",i);
				cb[i] = 1;//被标记
			}
		}
		int qq = 0;
		for(int i=1 ; i<=n ; i++){//查看有无未被记录的 
			if(cb[i] == 0){
				printf("%d\n",i);
				qq = 1;
				break;
			}
		}
//		printf("ans = %d\n",ans);
		if(qq == 0){//全部有 ,就输出最后一个 
			printf("%d\n",ans);
		}
	}
}

别人的代码

#include <iostream>
using namespace std;
const int m = 3;
int main()
{
    int n,m, f = 0;
    while(cin >> n >> m)
    {
        if(n +m == 0) break;
     
    for (int i = 1; i <= n; i++)
    f = (f + m) % i;
    cout << f + 1 << endl;
    }
}

代码来源: https://ac.nowcoder.com/acm/contest/view-submission?submissionId=45134874

约瑟夫环问题

我写的代码其实有一些问题,但能通过测评,看着别人的代码,感觉差距不小

用模拟来跑在大数据量的情况下占用时间和空间,不是很好的解法

其实对于约瑟夫环问题有着递推公式

图源自https://blog.csdn.net/u011500062/article/details/72855826![这里是引用](https://img-blog.csdnimg.cn/202010030012084.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0R1ZXNlcg==,size_16,color_FFFFFF,t_70#pic_center)

看图可以比较清楚直观的看出,我们的最后一位留下的是7 这时候它的下标是0 递推公式就是将这个过程反过来 每一轮去掉一位,然后从下一位又开始计算m,相当于是把下标前移了m位,每一轮重复这个过程,直到最后剩下的那个下标为0 反过来就是刚开始的那个下标为0,然后不断的循环从0开始按照规律往后加下标,因为往后的话会溢出需要取模,于是,递推公式就变成了每一轮的f(N,M)=(f(N−1,M)+M)%n

用代码来表示就是

int cir(int n,int m)
{
	int p=0;
	for(int i=2;i<=n;i++)
	{
		p=(p+m)%i;
	}
	return p+1;//下标要再加1
}

参考: https://blog.csdn.net/weixin_38214171/article/details/80352921 https://www.cnblogs.com/whiterock/p/8158812.html https://blog.csdn.net/u011500062/article/details/72855826(这个非常容易理解)