HDU 1216 Assistance Required(暴力打表)
传送门:
http://acm.hdu.edu.cn/showproblem.php?pid=1216
Assistance Required
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3158 Accepted Submission(s): 1662
The first contestant in the queue was asked for his number (which was 2). He was freed from the washing up and could party on, but every second contestant behind him had to go to the kitchen (those with numbers 4, 6, 8, etc). Then the next contestant in the remaining queue had to tell his number. He answered 3 and was freed from assisting, but every third contestant behind him was to help (those with numbers 9, 15, 21, etc). The next in the remaining queue had number 5 and was free, but every fifth contestant behind him was selected (those with numbers 19, 35, 49, etc). The next had number 7 and was free, but every seventh behind him had to assist, and so on.
Let us call the number of a contestant who does not need to assist with washing up a lucky number. Continuing the selection scheme, the lucky numbers are the ordered sequence 2, 3, 5, 7, 11, 13, 17, etc. Find out the lucky numbers to be prepared for the next contest party.
2
10
20
0
3
29
83
#include <stdio.h>
#include <string.h>
#define N 40000
int vis[];
int luck[]; void get_luck()
{ int i,j;
int k=; for(i=;i<=N;i++)
{
if(!vis[i])//i未被标记过
{
luck[k++]=i;//i为幸运数
printf("%d,",i);
int cnt=;
for(j=i+;j<=N;j++) //从i+1开始到N,从未被标记过的数中,每隔i-1个数,标记一下 ,
{ //被标记的数不是幸运数
if(!vis[j])
{
cnt++;
if(cnt==i)
{
cnt=;
vis[j]=;
}
}
}
}
} } int main()
{
// get_luck();
int n;
int a[]={,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,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,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,};
while(scanf("%d",&n) && n)
{
printf("%d\n",a[n]);
}
return ;
}
HDU 1216 Assistance Required(暴力打表)的更多相关文章
- HDU 1216 Assistance Required 埃拉托色尼色筛法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1216 思路:色筛法 代码(1): #include<iostream>//-------- ...
- 数学--数论--HDU 2582 F(N) 暴力打表找规律
This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gc ...
- HDU 1012 u Calculate e【暴力打表,水】
u Calculate e Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 暴力打表之hdu 2089
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 有两种方法: 1.数位DP算法 2.暴力打表——真是个好法子!!! 接下来是注意点: 1.一般这 ...
- HDU 5179 beautiful number (数位dp / 暴力打表 / dfs)
beautiful number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 1431 素数回文(暴力打表,埃托色尼筛法)
这题开始想时,感觉给的范围5 <= a < b <= 100,000,000太大,开数组肯定爆内存,而且100000000也不敢循环,不超时你打我,反正我是不敢循环. 这题肯定得打表 ...
- ACM/ICPC 之 暴力打表(求解欧拉回路)-编码(POJ1780)
///找到一个数字序列包含所有n位数(连续)一次且仅一次 ///暴力打表 ///Time:141Ms Memory:2260K #include<iostream> #include< ...
- XTU OJ 1210 Happy Number (暴力+打表)
Problem Description Recently, Mr. Xie learn the concept of happy number. A happy number is a number ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
随机推荐
- Android ContentProvider的介绍(很详细)
博客分类: android进阶 一.ContentProvider的概念 ContentProvider:为存储和获取数据提供统一的接口.可以在不同的应用程序之间共享数据.Android已经为常见 ...
- 6个Unity 开源项目分享!
http://gad.qq.com/article/detail/38279?sessionUserType=BFT.PARAMS.249034.TASKID&ADUIN=991655778& ...
- 坐标深圳 | Kubernetes!我要用这样的姿势拥抱你
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 从去年至今,容器.Kubernetes话题的热度就持续不减,有人说基于容器 +Kubernetes 的新型 PaaS 将会成为云计算的主流: ...
- 利用pandas生成csv文件
# -*- coding:UTF-8 -*- import json from collections import OrderedDict with open('dns_status.json',' ...
- 【Iftop】实时监控流量工具
linux基本查询流量的命令有: 1.ifconfig 只能看到当前接收和发送出去的总共的字节大小,但是不能看到网卡流量的实时发送情况 2.watch more /proc/net/dev 只有接受 ...
- log4net日记文件路径动态配置
在项目开发过程中,部署的服务器越来越多,查看日记的时候需要每台服务器去找日记看,这对运维人员来说是一个很不友好的方式.在此基础上就提出将所有日记统一到一台服务器上进行存放,并按照产生日记的服务器分文件 ...
- 【学习笔记】String进阶:StringBuffer类(线程安全)和StringBuilder类
一.除了使用String类存储字符串之外,还可以使用StringBuffer类存储字符串.而且它是比String类更高效的存储字符串的一种引用数据类型. 优点: 对字符串进行连接操作时,使用Strin ...
- web应用和http协议
一.web应用 Web应用程序是一种可以通过Web访问的应用程序: 程序的最大好处是用户很容易访问应用程序,用户只需要有浏览器即可,不需要再安装其他软件. 应用程序有两种模式C/S.B/S. 1.C/ ...
- js 的起源故事
"1994年,网景公司(Netscape)发布了Navigator浏览器0.9版.这是历史上第一个比较成熟的网络浏览器,轰动一时.但是,这个版本的浏览器只能用来浏览,不具备与访问者互动的能力 ...
- JSP初学者4
Filter可认为是Servlet的“加强版”,他主要用于对用户请求进行预处理,也可以对HttpServletResponse进行后处理,是个典型的 处理链. 使用Filter完整的流程是:Filte ...