Codejam Qualification Round 2016 - A,B,C题解
来源:互联网 发布:贴吧查发帖记录软件 编辑:程序博客网 时间:2024/06/16 00:36
A - Counting Sheep
题意:
给一个数N,问这个数的多少倍后(假设为i),1~iN中0~9就都至少出现一次了。输出iN。
题解:
除了0不可能外,其他的都可以有,暴力的做就好
Code:
#include <iostream>#include <cstdio>using namespace std;int had[10];int main(){int T,cases,x,y,m;freopen("A-large.in.txt","r",stdin);freopen("A-large.out","w",stdout);scanf("%d",&T);for (int cases=1;cases<=T;cases++){printf("Case #%d: ",cases);scanf("%d",&x);if (!x) puts("INSOMNIA"); else{ m=y=0; memset(had,false,sizeof(had)); while (m!=10){ y+=x; int t=y; while (t){ if (!had[t%10]) had[t%10]=true,m++; t/=10; } } printf("%d\n",y); }}return 0;}
B - Revenge of the Pancakes
题意:
有一个栈,里面的元素有-,+两个状态,可以做的操作是从栈顶取出若干个元素,将它们顺序反过来,然后状态反过来放回去,问给一个栈的状态,至少多少次操作可以让栈里的元素都为+。
题解:
观察后,得知操作是将栈中最上方连续的一块-变为+
Code:
#include <iostream>#include <cstdio>using namespace std;char s[105];int main(){int T,cases,n,ans;freopen("B-large.in.txt","r",stdin);freopen("B-large.out","w",stdout);scanf("%d",&T);for (int cases=1;cases<=T;cases++){printf("Case #%d: ",cases); scanf("%s",s+1),n=strlen(s+1);ans=0;if (s[1]=='-') ans=1;for (int i=2;i<=n;i++){if (s[i]==s[i-1]) continue;if (s[i]=='+') continue;ans+=2;}printf("%d\n",ans);}return 0;}
C - Coin Jam
题意:
我们称一个数为jamcoin当其
1、只包含0,1
2、以1开头,以1结尾
3、将其看作2~10进制,所得到的数都不是素数
输入N,J,则输出J个N位的符合要求的jamcoin,并且为了证明输出的数是jamcoin,输出其为成2~10进制时的非1与本身的一个约数
题解:
Miller-Rabin + Pollard_rho 参考这个代码
因为大数据比较大,改了一个python版本,且为了快速求解,可以多开几个进程同时枚举,我的机器开了4个进程,大数据大概就一刻分钟出来
import random def exp_mod(x,k,m): if (k==0): return 1 ans = exp_mod(x,k/2,m) ans = (ans * ans)%m if (k%2 == 1): return (ans * x)%m else: return ansdef Rabin_Miller(p): for times in range(1,10): a = random.randint(1,p-1) if (exp_mod(a,p-1,p) != 1): return False return Truedef gcd(a,b): if (b == 0): return a else: return gcd(b,a%b)def Pollard_rho(x,c): i = 1 k = 2 x0 = random.randint(0,x-1); y = x0 while (True): i = i + 1 x0 = (x0*x0+c)%x d = gcd(y-x0,x) if (d != 1) and (d != x): return d if (y == x0): return x if (i == k): y = x0 k = k + k def findfac(n): if (Rabin_Miller(n)): return n p = n while (p >= n): p = Pollard_rho(p,random.randint(1,n-1)) return findfac(p) fo = open('output.txt','w') def judge(x): t = x s = "" while (t > 0): s = str(t%2) + s t = t / 2 for p in range(2,11): m = 0 k = 1 t = x while (t > 0): if ( t % 2 == 1): m = m + k k = k * p t = t / 2 if (Rabin_Miller(m)): return False fac = findfac(m) s = s + " " + str(fac) fo.write(s + "\n") return True t = int(input())n = int(input())j = int(input())fo.write("Case #1:\n") #x = (2**32)+(2**9)+(2**6)+(2**4)+(2**2)+(2**1)+(2**0)x = (2**31)+(2**30)-1while j > 0: while judge(x) == False: x = x - 2 j = j-1 x = x - 2fo.close()
0 0
- Codejam Qualification Round 2016 - A,B,C题解
- Codejam 2008 qualification round question B
- Codejam 2008 qualification round question A
- Codejam 2008 qualification round question C
- Codejam 2009 qualification round question C
- Codejam 2010 qualification round question C
- codejam 2008 Qualification Round
- Google codejam Qualification Round 2015 B 巧妙枚举结果 + 贪心
- google codejam 2009 Qualification Round Problem C code
- Codejam Africa and Arabia 2011 qualification round question C
- Google CodeJam Qualification Round 2013
- Google CodeJam Qualification Round 2014
- Codeforces Round #438 C. Qualification Rounds 题解
- Codeforce Round #439 A B C 题解
- Qualification Round 2016(A. Counting Sheep,B. Revenge of the Pancakes,C. Coin Jam,D. Fractiles(构造))
- codejam 2016 Round A APAC Test
- 2012谷歌挑战赛CodeJam Round 1A problem B
- Croc Champ 2013 - Qualification Round A题解题报告
- uva10129
- HDU 5661 Claris and XOR
- 界面组件:选项卡
- POJ 3278 Catch That Cow
- nova
- Codejam Qualification Round 2016 - A,B,C题解
- intellj配置spark源码 attach
- Windows下的Objective-C集成开发环境(IDE)的搭建
- vm 四种网络连接方式,备用自己看看
- 动态规划算法——钢条切割问题
- iOS面试知识点之内存管理
- Python文件读取
- Java异常分类及区别
- JAVA集合(1)