日歷
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
27 | 28 | 29 | 30 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|
統計
- 隨筆 - 30
- 文章 - 0
- 評論 - 51
- 引用 - 0
導航
常用鏈接
留言簿(4)
隨筆分類
隨筆檔案
ACM
搜索
最新評論

閱讀排行榜
評論排行榜
|
摘要: 這幾天一直在修改這道題,一直都改不對,老是錯誤,提交不成功,我把自己的代碼貼出來讓大家幫忙看看,在這里謝過了!
#include <stdio.h>#include <string.h>#include <stdlib.h>int result[4];int reNumbe... 閱讀全文
昨天開始做 1423題,早上剛剛ac。其實這道題有好幾種方法,后來看了大家討論才去做的,不算是自己獨立思考。 第一種方法是根據stirling逼近來做,《計算機程序設計藝術》《算法導論》中給出了公式。 第二種是是取對數,寫了一個但是總是超時,后來看了 這篇blog,后悔自己當初為什么不想辦法改進自己的方法。 算是留個紀念,下次注意!
今天做完 1006題,第一次用枚舉法,但是時間復雜度大,后來看到帖子說是用中國余數法。自己試著也寫了一個,但是用時也過大,現在把代碼貼出來,請大家幫忙改一改啊!謝謝了!
1 #include <stdio.h> 2 3 int main(int argc, char* argv[]) 4  { 5 int p,e,i,d, index; 6 int day; 7 int x = 28*33*6; 8 int y = 23*33*19; 9 int z = 23*28*2; 10 index = 0; 11 12 13 do 14 { 15 scanf("%d %d %d %d", &p,&e, &i, &d); 16 if(p == -1 && e == -1 && i == -1 && d == -1) 17 break; 18 p = p%23; 19 e = e%28; 20 i = i%33; 21 day = (p*x + e*y + i*z) % 21252; 22 if(day == d) 23 day += 21252; 24 printf("Case %d: the next triple peak occurs in %d days.\n", ++index,day-d >= 0 ? day-d : day-d+21252); 25 }while(1); 26 return 0; 27 }
這是我做 1005題的代碼,希望大家看完之后能給予指導。
1 #include <stdio.h> 2 3 #define PI 3.141592 4 5 int Caculate(float x, float y) 6  { 7 int r = (int)((x*x + y*y) * PI / 100); 8 return r*100 >= (x*x + y*y)*PI ? r : r+1; 9 } 10 11 int main(int argc, char* argv[]) 12  { 13 int n, i; 14 float x,y; 15 int year; 16 scanf("%d", &n); 17 for(i = 1; i <= n; i++) 18 { 19 scanf("%f %f", &x, &y); 20 year = Caculate(x, y); 21 printf("Property %d: This property will begin eroding in year %d.\n", i, year); 22 } 23 printf("END OF OUTPUT.\n"); 24 25 return 0; 26 } 27 28
今天提交了 1004,但總覺得題意好像沒有這么簡單。先貼上自己的代碼,大家是怎么思考這道題的?
1 #include <stdio.h> 2 int main(int argc, char* argv[]) 3  { 4 int i; 5 float sum = 0, temp; 6 for(i = 0; i < 12; i++) 7 { 8 scanf("%f", &temp); 9 sum += temp; 10 } 11 printf("$%.2f", sum/12); 12 return 0; 13 }
今天做的 這道題感覺上面很奇怪,按照題目要求寫了代碼,但總覺得哪里有什么地方不對,還請大家多多指教!
1 #include <stdio.h> 2 int main(int argc, char* argv[]) 3  { 4 float s,sum = 0; 5 int i,j; 6 while(scanf("%f", &sum) == 1) 7 { 8 if(sum != 0) 9 { 10 j = 2; s = 0; 11 while(s < sum) 12 { 13 s += 1.0/j; 14 j++; 15 } 16 printf("%d card(s)\n", j-2); 17 } 18 else 19 break; 20 } 21 return 0; 22 }
摘要: 這道題我做的很郁悶,代碼也寫的不好、很長,方法也一般,有點麻煩,自己都覺得很爛,在提交的時候,發現別人的代碼寫的很簡練,但是不知道自己該怎么改進,希望大家多多提意見,謝謝大家了!
1#include <string.h> 2#include&... 閱讀全文
昨天晚上寫完了 這道題,早上過來提交。 主要用到了插入排序算法,并且參看了桶排序算法,如果大家有什么好的想法,希望能夠共享一下,嘿嘿!我的代碼有哪里寫的不好,也請大家指教!
1 #include <stdlib.h> 2 #include <stdio.h> 3 typedef struct dNANumber 4  { 5 char ch[100]; 6 int count; 7 }DNANumber; 8 9 void Sort(DNANumber *arr, int rows) 10  { 11 int i, j; 12 DNANumber temp; 13 for(i = 1; i < rows; i++) 14 { 15 temp = arr[i]; 16 for(j = i-1; j >= 0; j--) 17 { 18 if(arr[j].count > temp.count) 19 arr[j+1] = arr[j]; 20 else 21 break; 22 } 23 arr[j+1] = temp; 24 } 25 return; 26 } 27 28 int Index(char ch) 29  { 30 switch(ch) 31 { 32 case 'A': 33 return 0; 34 case 'C': 35 return 1; 36 case 'G': 37 return 2; 38 case 'T': 39 return 3; 40 } 41 } 42 43 void CountNumber(DNANumber *dna, int length) 44  { 45 int count = 0; 46 int letter[4] = {0,0,0,0}; 47 int i, j; 48 int temp; 49 50 for(i = 0; i < length; i++) 51 { 52 letter[Index(dna->ch[i])]++; 53 } 54 55 for(i = length-1; i >= 0; i--) 56 { 57 temp = Index(dna->ch[i]); 58 for(j = temp+1; j < 4; j++) 59 { 60 count += letter[j]; 61 } 62 letter[temp]--; 63 } 64 dna->count = count; 65 return; 66 } 67 int main(int argc, char* argv[]) 68  { 69 int length = 0, rows = 0; 70 int i; 71 DNANumber dnaArray[10000]; 72 //DNANumber *dna; 73 74 scanf("%d %d", &length, &rows); 75 for(i = 0; i < rows; i++) 76 { 77 dnaArray[i].count=0; 78 scanf("%s", dnaArray[i].ch); 79 CountNumber(&dnaArray[i], length); 80 } 81 82 Sort(dnaArray, rows); 83 84 for(i = 0; i < rows; i++) 85 { 86 printf("%s\n", dnaArray[i].ch); 87 } 88 return 0; 89 } 90 91 92
在上周開始做北大acm1002題,經過幾天的分析和參考別人的代碼,最后終于提交成功了。在這里把代碼貼出來,和大家分享,也懇請大家指出寫不好的地方。在網上搜到了另外一個人對這道題的解法,他是解法,推薦大家看看。
1 #include <stdlib.h> 2 #include <stdio.h> 3 typedef int TelNumber; 4 int toNumber[26] = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,-1,7,7,8,8,8,9,9,9,-1}; 5 6 void SortNumber(TelNumber *tel, int left, int right) 7  { 8 int j,i; 9 TelNumber temp; 10 do 11 { 12 i = left; 13 j = right; 14 temp = tel[(i+j)/2]; 15 do 16 { 17 while(tel[i] < temp) i++; 18 while(tel[j] > temp) j--; 19 if(i > j) 20 break; 21 if(i < j) 22 { 23 TelNumber t = tel[i]; 24 tel[i] = tel[j]; 25 tel[j] = t; 26 } 27 i++;j--; 28 }while(i <= j); 29 30 if(j-left <= right -i) 31 { 32 if(left < j) 33 SortNumber(tel,left, j); 34 left = i; 35 } 36 else 37 { 38 if(i < right) 39 SortNumber(tel, i, right); 40 right = j; 41 } 42 }while(left < right); 43 } 44 45 int main(int argc, char* argv[]) 46  { 47 int count; 48 int i; 49 int t = 1; 50 int bSame = 0; 51 TelNumber tel[100000]; 52 scanf("%d\n", &count); 53 for( i = 0; i < count;i++) 54 { 55 char ch; 56 tel[i] = 0; 57 while( ch = getchar(), ch != '\n') 58 { 59 if(ch == '-') 60 continue; 61 else if (ch >= '0' && ch <= '9') 62 tel[i] = tel[i]*10 + (ch-'0'); 63 else if((ch >= 'A' && ch <= 'P') || (ch >= 'R' && ch <= 'Y')) 64 tel[i] = tel[i]*10 + toNumber[ch-'A']; 65 } 66 } 67 68 SortNumber(tel, 0, count-1); 69 for(i = 0; i < count;) 70 { 71 for(t = i+1; (t < count) && (tel[i] == tel[t]); t++) 72 ; 73 if(t-i > 1) 74 { 75 bSame = 1; 76 printf("%03d-%04d %d\n", tel[i]/10000, tel[i]%10000, t-i); 77 } 78 i=t; 79 } 80 if(bSame==0) 81 printf("No duplicates.\n"); 82 return 1; 83 }
摘要: 今天下午做了一道acm的題,提交了10次都是WA,所以想請大家幫我看看到底哪里不正確,程序哪里寫的不好!謝謝大家了!代碼:
1#include <stdlib.h> 2#include <stdio.h> 3typedef struct telNumber ... 閱讀全文
|