上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 27 下一页
摘要: 1)当n为1,无解。2)n为偶数2^x显然为偶数,而1为奇数,2^n和1不可能关于n同余,x无解。3)n为奇数时(n与2互素),由费尔马定理知当x=n-1为一解(但不一定是最小),此时暴力即可。**值得注意的是,暴力时为了减小运算量,可以先取摸,再乘2,即代码中的i=(i%n)*2。否则会TLE。#include <stdio.h>int main(){ int n,i,j; while(scanf("%d",&n)==1){ if(n%2==0||n==1) printf("2^? mod %d = 1\n",n); else{ f 阅读全文
posted @ 2013-04-11 20:48 执着追求的IT小小鸟 阅读(202) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1201这题一直搞不清楚第一年和最后一年怎么放到循环里,后来发现没有和谐的方法,所以一个一个拆开了View Code 1 #include<stdio.h> 2 int leap(int year) 3 { 4 if((year%4==0&&year%100!=0)||(year%400==0)) 5 return 1; 6 else return 0; 7 } 8 int main() 9 {10 int y,m,d,sum,i,n;11 scanf("%d", 阅读全文
posted @ 2013-04-11 16:24 执着追求的IT小小鸟 阅读(165) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1877感觉应该是很水的一题,但是代码却是wa了,在网上找到一个牛逼的函数itoa(a+b,ch,m);能够自动按m进制转换错误代码View Code 1 #include<stdio.h> 2 void print(long n,int m) 3 { 4 char s[100000]; 5 int i=0; 6 while(n) 7 { 8 s[i++]=n%m+'0'; 9 n/=m;10 }11 i--;12 while(i>=0)1... 阅读全文
posted @ 2013-04-10 16:27 执着追求的IT小小鸟 阅读(98) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2106简单的进制转化View Code 1 #include<stdio.h> 2 int main() 3 { char s[100]; 4 int sum,n,i,a,b,t,m; 5 while(scanf("%d",&n)!=EOF) 6 { 7 m=0; 8 while(n--) 9 {10 sum=0;11 scanf("%s",s);12 f... 阅读全文
posted @ 2013-04-09 22:53 执着追求的IT小小鸟 阅读(124) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2097解法同1197,输出有些不一样而已View Code 1 #include <stdio.h> 2 int main() 3 { 4 int i, n, sum10, sum12, sum16,a[10000]; 5 for (i=1000; i<10000; i++){ 6 n = i; 7 sum10 = 0; 8 while (n){ 9 sum10 += n%10;10 n /= 1... 阅读全文
posted @ 2013-04-09 22:42 执着追求的IT小小鸟 阅读(227) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1266View Code 1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int n,i,j; 6 char s[10000]; 7 scanf("%d",&n); 8 gets(s); 9 while(n--)10 {11 gets(s);12 i=strlen(s)-1;13 while(s[i]=='0')14 i--;1... 阅读全文
posted @ 2013-04-09 20:15 执着追求的IT小小鸟 阅读(112) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1412把两个集合合并为一个,然后进行排序,最后把不重复的数输出View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 int cmp(const void *a,const void *b) 4 { 5 return *(int *)a-*(int *)b; 6 } 7 int main() 8 { 9 int n,m,s[100000],i;10 while(scanf("%d%d",&n,&m)! 阅读全文
posted @ 2013-04-09 19:01 执着追求的IT小小鸟 阅读(138) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1058见注释View Code 1 #include<stdio.h>//解法同uva里的136题,丑数,要先打表,然后再输出 2 int min(int a,int b) 3 { 4 if(a>=b) 5 return b; 6 else return a; 7 } 8 int main() 9 {10 int a[5843],b[4];11 int i,j,temp,a1,a2,a3,n;12 a[1]=1; 13 for(i=1;i<=5842;)14 {15 ... 阅读全文
posted @ 2013-04-09 12:19 执着追求的IT小小鸟 阅读(230) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2019边输入,边判断,边插入,在插入后要做个标记,避免重复插入View Code 1 #include<stdio.h> 2 int main() 3 { 4 int x,n,a[10000],i,t,flag; 5 while(scanf("%d%d",&n,&x)&&(n||x)) 6 { 7 flag=0; 8 scanf("%d",&a[0]); 9 if(x<a[0])10 {11 t=x... 阅读全文
posted @ 2013-04-09 12:18 执着追求的IT小小鸟 阅读(204) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1279角谷猜想就是很多oj上面都有提到的3n+1的问题,uhunt上面的100;这题基本思路跟那题是一样的,就是在按格式输出上面有些不一样,第一奇数输出用printf(“%d”,a);接下来的就用printf(“ %d”,a);,可以保证最后一个没有空格View Code #include<stdio.h>int main(){ int n,a,i,flag,t=0; scanf("%d",&n); while(n--) { flag=0; scanf("%d 阅读全文
posted @ 2013-04-08 00:07 执着追求的IT小小鸟 阅读(170) 评论(0) 推荐(0) 编辑
上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 27 下一页