12 2012 档案

摘要:无重载View Code #include <cstdio>#include <cstring>#define maxn 103int n, k, mod;int ret[maxn][maxn], e[maxn][maxn];void mult(int a[maxn][maxn], int b[maxn][maxn]){ int i, j, k; int c[maxn][maxn] = {0}; for(i = 0; i < 2*n; i++) for(j = 0; j < 2*n; j++) { for(k = 0; k <... 阅读全文
posted @ 2012-12-19 18:47 To be an ACMan 阅读(217) 评论(0) 推荐(0)
摘要:递归View Code #include <cstdio>#include <cstring>#define LL __int64LL a, b, x, y, mod, n;void gao(LL n, LL &x, LL &y){ if(n == 1) { x = a % mod, y = b % mod; return; } LL tx, ty; gao(n>>1, tx, ty); x = (tx * tx - ty * ty) % mod; y = 2 * tx * ty % mod; if(n & 1) ... 阅读全文
posted @ 2012-12-16 14:38 To be an ACMan 阅读(216) 评论(0) 推荐(0)
摘要:A.暴力, 水题B.n <= 2 都输出-1, 其它必然存在一对满足题意的数, 而且 这对数相邻, 注意到这点的话,就容易做多了,直接暴力找解View Code #include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[100005], b[100005];int main(){ int i, j, n; scanf("%d", &n); for(i = 0; i < n ;i++) scanf("%d" 阅读全文
posted @ 2012-12-13 20:32 To be an ACMan 阅读(199) 评论(0) 推荐(0)
摘要:View Code #include <cstdio>#include <cstring>#include <algorithm>using namespace std;char map[404][404];int a[404][404]; int n, m, k, sum;__int64 ans;int cnt[33]; int main(){ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout 阅读全文
posted @ 2012-12-12 16:49 To be an ACMan 阅读(469) 评论(0) 推荐(0)
摘要:A题水题B题:二分View Code #include<cstdio>#include<cstring>#include<algorithm>using namespace std;int n, m;int a[100005];int main(){ int i, j; freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); while( ~scanf("%d", &n 阅读全文
posted @ 2012-12-09 17:48 To be an ACMan 阅读(210) 评论(0) 推荐(0)
摘要:View Code #include<cstdio>#include<cstring>int q[103], p[103], s[103], pp[103];int n, k, a, b;int main(){ int i, j; scanf("%d%d", &n, &k); for(i = 1; i <= n; i++) scanf("%d", &q[i]); for(i = 1; i <= n; i++) scanf("%d", &s[i]); //求解操作1的周 阅读全文
posted @ 2012-12-07 19:59 To be an ACMan 阅读(313) 评论(0) 推荐(0)
摘要:失算啊,水题啊,比赛没AView Code #include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[100005], b[100005];int main(){ int i, j, n; scanf("%d", &n); for(i = 0; i < n ;i++) scanf("%d", &a[i]), b[i] = a[i]; if(n <= 2) { puts("-1" 阅读全文
posted @ 2012-12-07 16:17 To be an ACMan 阅读(321) 评论(0) 推荐(0)
摘要:比赛时我用单调队列A的View Code #include<cstdio>#include<cstring>#include<queue>using namespace std;#define LL __int64int a, n, d;LL ans;queue <int> q;int main() { int i, j; scanf("%d%d", &n, &d); for(i = 0; i < n; i++) { scanf("%d", &a); q.push(a); wh 阅读全文
posted @ 2012-12-07 15:41 To be an ACMan 阅读(359) 评论(1) 推荐(0)
摘要:View Code #include<cstdio>#include<cstring>int n, sum, p;void gao(int &sum, int &p){ while(sum >= 10) { p = 0; while(sum) p += sum % 10, sum /= 10; sum = p; }}int main(){ int i, j; while( ~scanf("%d", &n) && n) { sum = 1; ... 阅读全文
posted @ 2012-12-05 12:42 To be an ACMan 阅读(136) 评论(0) 推荐(0)
摘要:View Code #include<cstdio> #include<cstring> __int64 n, p, a[4] = {2, 3, 5, 7}; int main() { int i, j; while( ~scanf("%I64d", &n) && n) { __int64 ans = 1; for(i = 0; i < 4; i++) { __int64 m = n; p = 0; ... 阅读全文
posted @ 2012-12-04 23:19 To be an ACMan 阅读(158) 评论(0) 推荐(0)
摘要:题意:统计n!后面有几个0, 2肯定够用,只要算n!里有几个5就可以了View Code #include<cstdio>#include<cstring>int main(){ int cas, n; scanf("%d", &cas); while(cas--) { scanf("%d", &n); int s = 5, ans = 0; while(s <= n) ans += n/s, s *= 5; printf("%d\n", ans); } return 0;} 阅读全文
posted @ 2012-12-04 22:01 To be an ACMan 阅读(159) 评论(0) 推荐(0)
摘要:分成2段a和b,若n为奇数, a,b一奇一偶, 若n为偶数,a,b都为偶数。假设长度为L,每段的次数是 1+2+3+......+L = (L+1)*L/2, a,b两段加起来就是答案;View Code #include<cstdio>#include<cstring>__int64 n, a, b;int main(){ while( ~scanf("%I64d", &n)) a = n>>1, b = n - a, printf("%I64d\n", (a*a+b*b-n)>>1); retu 阅读全文
posted @ 2012-12-04 21:47 To be an ACMan 阅读(186) 评论(0) 推荐(0)
摘要:View Code #include<cstdio>#include<cstring>#include<cmath>bool vis[10004];void init() { int i, j; for(i = 2; i * i <= 10000; i++) for(j = i*i; j <= 10000; j += i) vis[j] = 1; vis[1] = 1; //注意}int main(){ int n, i; // 注意14 = 7 + 7 init(); while( ~scanf("%d", &n)) 阅读全文
posted @ 2012-12-04 21:18 To be an ACMan 阅读(144) 评论(0) 推荐(0)
摘要:View Code #include<cstdio>#include<cstring>#include<cmath>int p[1004], tot;bool vis[1104];void init() // 素数打表,注意本题1也是素数{ int i, j; for(i = 2; i * i <= 1000; i++) for(j = i*i; j <= 1000; j += i) vis[j] = 1; for(i = 1; i <= 1000; i++) if(!vis[i])p[tot++] = i; }int mai... 阅读全文
posted @ 2012-12-04 21:09 To be an ACMan 阅读(250) 评论(0) 推荐(0)
摘要:很详细的资料:http://blog.csdn.net/lulipeng_cpp/article/details/7612490补充以下结论,自己推的,解释了以上博客里的疑惑。方程ax+by=gcd(a,b),即 模线性方程ax≡d(mod b) ,令d =gcd(a,b)。假设模线性方程的解为 x0, y0。结论1:则有 max( abs(x0),abs(y0) )< max( abs(a), abs(b) );结论2:若d = a, 则 x = 1,y = 0; 若 d = b,则 x = 0,y = 1;结论3:则方程的所有解为 x = x0 + b/d*i, y = y0 - a 阅读全文
posted @ 2012-12-04 19:55 To be an ACMan 阅读(436) 评论(0) 推荐(0)
摘要:View Code #include<cstdio>#include<cstring>int p[15] = {1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29};int a[15];int main(){ int i, j, k, n; while( ~scanf("%d", &n) && n) { printf("%d = ", n); int s = 1; for(i = 0; i < 13; i++) { s *= p[i]; if(... 阅读全文
posted @ 2012-12-03 21:40 To be an ACMan 阅读(214) 评论(0) 推荐(0)
摘要:题意:n对数,大小为1、2、3、...、n。现要求两个1之间有1个数,两个2之间有2个数,以此类推,两个n之间有n个数,并且,数的次序可以随意的。解法:我们用sum()表示求和运算。1.设k(k=1,2,..,n)放置的第一个位置为ak,第二个位置为bk。显然有bk-ak=k+1(ak<bk)那么会有sum(bk-ak)=2+3+4+...+(n+1)=(1+2+3+...+n)+(1+1+...+1)=n*(n+3)/2。2.又因为要有2*n个位置来放置这2*n个数。则sum(ak+bk)=1+2+3+...+2*n=(1+2*n)*(2*n)/2=(1+2*n)*n。3.sum(ak 阅读全文
posted @ 2012-12-03 20:39 To be an ACMan 阅读(812) 评论(0) 推荐(0)
摘要:View Code #include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>using namespace std;const int maxn = 100100;vector < pair<int, int> > v;vector <int> a, b, c;#define ALL(c) c.begin(), c.end()int main(){ int i, j; for(i = 阅读全文
posted @ 2012-12-01 20:40 To be an ACMan 阅读(138) 评论(0) 推荐(0)