Hdu 1014 Uniform Generator
2012-07-22 15:27
211 查看
数学题,用hash记录元素出现次数,有重复那么马上退出。循环次数最多为mod次就可以判断是否重复。
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
const int maxn = 100001;
int hash[maxn];
int main()
{
int step, mod;
while(~scanf("%d%d", &step, &mod))
{
int i;
int flag = 0;
int ans = 0;
memset(hash, 0, sizeof(hash));
hash[0] = 1;
for(i = 1; i < mod ; i++)
{
ans = (ans+step)%mod;
hash[ans]++;
if(hash[ans] >= 2)
{
flag = 1;
break;
}
}
printf("%10d%10d ", step, mod);
printf(!flag?"Good Choice\n\n":"Bad Choice\n\n");
}
return 0;}
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
const int maxn = 100001;
int hash[maxn];
int main()
{
int step, mod;
while(~scanf("%d%d", &step, &mod))
{
int i;
int flag = 0;
int ans = 0;
memset(hash, 0, sizeof(hash));
hash[0] = 1;
for(i = 1; i < mod ; i++)
{
ans = (ans+step)%mod;
hash[ans]++;
if(hash[ans] >= 2)
{
flag = 1;
break;
}
}
printf("%10d%10d ", step, mod);
printf(!flag?"Good Choice\n\n":"Bad Choice\n\n");
}
return 0;}
相关文章推荐
- hdu_1014(竟然真的还有更水的)
- HDU 1014 — Uniform Generator
- hdu 1014 Uniform Generator(水 枚举 gcd)
- HDU 1014 Uniform Generator【公约数】
- 1014 hdu 统计问题
- hdu_1014_Uniform Generator_201310141958
- HDU 1014 Uniform Generator
- HDU 1014
- hdu 1059/ poj 1014 多重背包
- zoj 1149 && hdu 1059 && poj 1014 Dividing
- poj1014 hdu1059 Dividing 多重背包
- hdu1014 Uniform Generator
- Hdu 1059 Dividing & Zoj 1149 & poj 1014 Dividing(多重背包)
- hdu 1014 Uniform Generator【模拟 && 欧几里得】
- POJ 1014 && HDU 1059 Dividing(完全背包问题)
- hdu 1014(数学)
- [JAVA][HDU 1236][九度 1014][排名]
- HDU 1014 字符串处理
- HDU 1014 Uniform Generator
- hdu 1014 Uniform Generator