04 2013 档案
uva10125 - Sumsets
摘要:最简单的暴力 会超时所以我们要想方设法的减少循环层数或者循环次数,a+b+c = d那么a+b=d-c这不是简单的等式变形而是意味着我们循环的次数减少了。我们对于d和c分别用一层循环,对于a+b只用一层循环。很妙的转变,,,代码如下:#include #include using namespace std; int a[1010]; int main () { int n; while(scanf("%d",&n),n) { for(int i = 0; i = 0; i--) { for(int j = n... 阅读全文
posted @ 2013-04-30 21:33 Primo... 阅读(144) 评论(0) 推荐(0)
uva188 - Perfect Hash(完美哈希)
摘要:思路不难。重要的是理解题意。。。照着题意写代码。。。代码如下:#include #include #include using namespace std; char s[300]; int w[300]; int main () { while(gets(s)) { int len = strlen(s), tt = 0, n = 0, min_ = 2147483645; for(int i = 0, f = 0; i tt?tt:min_; tt = 0; f = 0;} continue; } tt = (t... 阅读全文
posted @ 2013-04-30 20:56 Primo... 阅读(182) 评论(0) 推荐(0)
nefu2 - 猜想
摘要:遍历2-n/2的所有的数,如果i和n-i都是素数的话就累加上1。。。代码如下:#include #include #define M 16777250 bool is_prime[M]; void judge() { int len = sqrt(M+0.5); for(int i = 2; i <= len; i++) if(is_prime[i]==0) for(int j = i*i; j <= M; j+=i) is_prime[j] = 1; } int main () { int n; judge(); while(scanf("... 阅读全文
posted @ 2013-04-30 14:08 Primo... 阅读(111) 评论(0) 推荐(0)
nefu117 - 素数个数的位数
摘要:以前没注意到floor()返回的是double型的数据,素数定理的应用,,,代码如下:#include #include int main () { long long n; while(scanf("%lld",&n)==1) { double tt = log10(n)+log10(log(10.0)); printf("%.0lf\n",floor(n-tt)+1); } return 0; } 犯错代码:#include #include int main () { long long n; ... 阅读全文
posted @ 2013-04-30 13:47 Primo... 阅读(146) 评论(0) 推荐(0)
nefu84 - 五指山
摘要:扩展欧几里德算法列方程dt-ln = y-x求基础解,在求最小t解代码如下:#include void gcd(long long a, long long b,long long &d,long long &x, long long &y) { if(b==0) {x = 1; y = 0; d = a;} else {gcd(b,a%b,d,y,x); y-=(a/b)*x;} } int main () { long long n, d, x, y; int cas; scanf("%d",&cas); while(cas--) ... 阅读全文
posted @ 2013-04-28 21:38 Primo... 阅读(114) 评论(0) 推荐(0)
poj1061 - 青蛙的约会
摘要:认真读题,画坐标图,得出方程:(n-m)t + k*L = (x-y)运用扩展欧几里德,解出一个基本解,然后由这个基本解,计算出最小的x值因为得到的基本解中x不一定是尽量小的正整数。所以我们要换算由于x的变化通式是x+k*bb;k 为任意整数,bb = b/gcd;所以最小的x是(x%bb+bb)%bb;代码如下:#include void gcd(long long a, long long b,long long &d,long long &x, long long &y) { if(b==0) {x = 1; y = 0; d = a;} else {gcd(b, 阅读全文
posted @ 2013-04-28 20:27 Primo... 阅读(149) 评论(0) 推荐(0)
扩展欧几里德算法
摘要:自己写出来的代码,求方程aX+bY=c的任意10组解。代码如下;#include void gcd(int a, int b, int &x, int &y, int &d) { if(b==0) {d = a; x = 1; y = 0;} else {gcd(b,a%b,y,x,d); y -= (a/b)*x;} } int main () { int a, b, c; while(scanf("%d%d%d",&a,&b,&c)==3) { int x, y, g; gcd(a,b,x,y,g); ... 阅读全文
posted @ 2013-04-28 19:35 Primo... 阅读(132) 评论(0) 推荐(0)
uva128 - 软件CRC
摘要:不算的对原串进行取余,,做后结合余数得出CRC码r是最后的余数,m是34943,因为(r*256*256+c)%m==0所以最小的c是使得(r*256*256+c)==m的值所以c = m-(r*256*256)%m代码如下:#include #include #define M 1100 char s[M]; const int m = 34943; int solve(int len) { long long ans = 0; for(int i = 0; i < len; i++) ans = (ans*256+s[i])%m; return ... 阅读全文
posted @ 2013-04-27 17:09 Primo... 阅读(144) 评论(0) 推荐(0)
uva10006 - Carmichael Numbers
摘要:水题。。。。模运算+素数打表+遍历。关键是把题意读懂。题意:对于所给的每个n判断是否符合条件。条件是n不是素数&&任意的2~n-1区间中的数都满足a^n%n==a思路:先判断是不是素数,然后判断是否符合第二个条件;代码如下:#include #include #include #define M 65010 bool prime[M]; void is_prime() { int len = sqrt(M+0.5); memset(prime,0,sizeof(prime)); for(int i = 2; i <= len; i++) if(prime[i]=... 阅读全文
posted @ 2013-04-26 20:58 Primo... 阅读(116) 评论(0) 推荐(0)
poj3232 - Accelerator(加速器)
摘要:这个题是我在比赛的时候看到的。开始的时候,身为菜鸟的我根本没想到用什么二分。。。。后来从别人那里知道了以后就火速的敲代码,上交,结果WA。接着我继续搞代码,越搞越乱。弄了好久也没弄出来其实是我少了个特判。那就是k=1的时候。因为k-1做了分母,所以k是不能等于1 的。由于没找到弊病,所以我和以为同伴在源代码的基础上改了又改,连续交了12遍都没过。最后。好吧。我们都放弃了。第二天等头脑清醒了,才改掉错误终于AC了。代码如下:#include #include #define M 100010 int a[M], n, k, m, max; int ok(int ans) { lon... 阅读全文
posted @ 2013-04-25 17:04 Primo... 阅读(207) 评论(0) 推荐(0)
uva138 - Street Numbers
摘要:推荐一位大神的题解。。。。http://caoyaqiang.diandian.com/post/2012-08-27/40038947597用到了佩尔方程。。。。表示没看懂。。。!!自己的代码#include int main () { int m = 17, k = 6, _m, _k; for(int i = 0; i int main () { printf( " 6 8\n"); printf( " 35 49\n"); printf( " 204 288\... 阅读全文
posted @ 2013-04-23 20:47 Primo... 阅读(115) 评论(0) 推荐(0)
国内外OJ简介
摘要:主流的几个像POJ、ZOJ、HDUOJ、HOJ(哈工大)、HUST(华中科大)的几个就不介绍了!下面介绍几个很不错但是很少人知道的OJ!希望对读者有些许帮助!以下的介绍顺序不是按任何顺序排列的,为看到想到才写的!若有不妥之处,请读者见谅!!Vijos(Velocious Informatics Judge Online System)地址:http://www.vijos.cn/介绍: Vijos是Vivian Snow是湖南师大附中的刘康(个人主页是http://www.viviansnow.cn/)搞的一个Judge系统,本来是作为创新大赛作品的,后来就搞起来了,现在人气很旺.但是Vij. 阅读全文
posted @ 2013-04-23 14:02 Primo... 阅读(327) 评论(0) 推荐(0)
ecnu1009 - 整数的拆分
摘要:理论上说是用了母函数理论。不过我喜欢通俗的解释。对于1~n每个数。我们从1开始,1可以组成1~n任何一个数,所以ans[i] = 1;(1 int a[121], b[121]; int main () { int n; while(scanf("%d",&n)==1) { for(int i = 0; i <= n; i++) {a[i] = 1; b[i] = 0;} for(int i = 2; i <= n; i++) { for(int j = 0; j <= n; j++) ... 阅读全文
posted @ 2013-04-23 13:13 Primo... 阅读(181) 评论(0) 推荐(0)
uva10795 - A Different Task(新汉诺塔问题)
摘要:这个题不同的是开始状态不规则,目标状态也不规则我们这里有个折中的方法,就是从开始和目标两个状态同时向一个参考状态移动。我们分析这个问题,会发现我们必须先把最大的圆盘放到目标位置,所以目前位置s和目标位置p上都不能存在其他比当前圆盘小的圆盘,然后把最大的圆盘从s移动到p上,所以ans等于把其他的圆盘从s移动到中转位置的步骤数step1加上把其他的圆盘从p移动到中转位置的步骤数step2再加上1所以ans = step1+step2+1;其他的移动方式和经典的汉诺塔差不多了,不过我们发现总共3个位置,要想把其他的圆盘移动到中转位置上,s和p位置上除了当前圆盘外都是空的,那么中转位置上肯定是有序的, 阅读全文
posted @ 2013-04-22 20:51 Primo... 阅读(238) 评论(0) 推荐(0)
UVA11384 - Help is needed for Dexte(正整数序列)
摘要:大水题,自己在纸上算几个值就能看出规律。代码如下:#include int fun(int n) { if(n==1) return 1; return fun(n/2)+1; } int main () { int n; while(scanf("%d",&n)==1) printf("%d\n",fun(n)); return 0; } 阅读全文
posted @ 2013-04-22 19:33 Primo... 阅读(121) 评论(0) 推荐(0)