上一页 1 ··· 8 9 10 11 12 13 14 下一页
  2012年4月5日
摘要: 实现自Matrix67!//定义:32位的整数的前16位为高位,后16位为低位//高低位交换#include <stdio.h>int main() { int n; while (scanf("%d", &n) != EOF) { int s, s1, s2; s1 = ((1 << 16) - 1) & n; s2 = s1 ^ n; s = (s1 << 16) | (s2 >> 16); printf ("%d\n", s); } return 0;}//定义:32位的整数的前16位 阅读全文
posted @ 2012-04-05 12:18 Try86 阅读(444) 评论(0) 推荐(0)
摘要: 实现自Matrix67!//计算二进制中的1的个数//分治思想#include <stdio.h>int main() { int n; while (scanf("%d", &n) != EOF) { n = (n & 0x55555555) + ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); n = (n & 0x0F0F0F0F) + ((n >> 4) & 0x0F0 阅读全文
posted @ 2012-04-05 12:13 Try86 阅读(203) 评论(0) 推荐(0)
摘要: 实现自Matrix67!//二进制中的1有奇数个还是偶数个//实现一#include <stdio.h>int main() { int n; while (scanf("%d", &n) != EOF) { int c = 0; while (n) { c += n & 1; n >>= 1; } if (c & 1) printf ("奇数个\n"); else printf ("偶数个\n"); } return 0;}//实现二//分治思想#inc... 阅读全文
posted @ 2012-04-05 12:12 Try86 阅读(565) 评论(0) 推荐(0)
摘要: 参考自Matrix67!//二分查找32位整数的前导0个数//二分查找思想#include <stdio.h>int main() { unsigned int n; while (scanf("%u", &n) != EOF) { if (n == 0) printf ("32\n"); else { int s = 1; if ((n >> 16) == 0) {s += 16; n <<= 16;} if ((n >> 24) == 0) {s += 8; n <<= 8;} .. 阅读全文
posted @ 2012-04-05 12:10 Try86 阅读(643) 评论(0) 推荐(0)
摘要: 详细理论请参考Matrix67!//去掉最后一位,相当于除于2#include <stdio.h>int main() { int n; while (scanf("%d", &n) != EOF) { printf ("%d\n", n>>1); } return 0;}//在最后加一个0,相当于乘于2#include <stdio.h>int main() { int n; while (scanf("%d", &n) != EOF) { printf ("%d\n&q 阅读全文
posted @ 2012-04-05 07:39 Try86 阅读(207) 评论(0) 推荐(0)
  2012年4月4日
摘要: //数论,判断两数是否互质#include <cstdio>#include <iostream>using namespace std;int gcd(int a, int b) { return b ? gcd(b, a%b) : a;}int main() { int t; scanf ("%d", &t); while (t--) { int n, m; scanf ("%d%d", &m, &n); if (gcd(n, m) == 1) printf ("NO\n"); el 阅读全文
posted @ 2012-04-04 20:52 Try86 阅读(131) 评论(0) 推荐(0)
摘要: //简单字符串处理#include <cstdio>#include <cstring>#include <iostream>using namespace std;char text[100005];int s[26];int main() { while (gets(text)) { int l = strlen(text); int i; for (i=0; i<26; ++i) s[i] = 0; for (i=0; i<l; ++i) ++s[text[i]-'a']; for (i=0; i<26; ++i... 阅读全文
posted @ 2012-04-04 20:13 Try86 阅读(218) 评论(0) 推荐(0)
摘要: //数学,没化简,直接用#include <cstdio>#include <iostream>using namespace std;int main() { int n; while (scanf("%d", &n) != EOF) { int s = n * n * n; int ans = (s-4)*4 + 6*(n-2)*(s-5) + 3*(n-2)*(n-2)*(s-6) + (n-2)*(n-2)*(n-2)*(s-7)/2; printf ("%d\n", ans); } return 0;} 阅读全文
posted @ 2012-04-04 20:04 Try86 阅读(161) 评论(0) 推荐(0)
摘要: //数学//参考______________白白の屋/*m=n^n,两边分别对10取对数得 log10(m)=n*log10(n),得m=10^(n*log10(n)),由于10的任何整数次幂首位一定为1,所以m的首位只和n*log10(n)的小数部分有关*/#include <cmath>#include <cstdio>#include <iostream>using namespace std;int main() { int t; scanf ("%d", &t); while (t--) { int n; scanf ( 阅读全文
posted @ 2012-04-04 16:58 Try86 阅读(203) 评论(0) 推荐(0)
摘要: 串中出现01时,在下一步后就会出现连续的两个0规律:i为偶数时:f[i] = f[i-1] * 2 + 1; i为奇数时:f[i] = f[i-1] * 2 - 1。//规律+打表+java大数import java.util.Scanner;import java.math.BigInteger;public class CT{ public static void main(String args[]) { Scanner cin = new Scanner(System.in); BigInteger []f = new BigInteger[10... 阅读全文
posted @ 2012-04-04 14:59 Try86 阅读(237) 评论(0) 推荐(0)
上一页 1 ··· 8 9 10 11 12 13 14 下一页