您的位置:首页 > 其它

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;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: