syhd142 |
|
|||
日歷
統計
導航常用鏈接留言簿(2)隨筆檔案(23)文章分類(270)
文章檔案(122)我的豆瓣搜索最新評論
閱讀排行榜
評論排行榜 |
題意:給你一個薩克斯演奏曲,每個音符只有固定的幾個手指可以彈奏,彈奏每個音符的手指不能是上次彈奏的手指,問每個手指彈奏了多少次。 解法:暴力打表。 #include <stdio.h>
#include <string.h> int table[14][11] = { 0,0,1,1,1,0,0,1,1,1,1, 0,0,1,1,1,0,0,1,1,1,0, 0,0,1,1,1,0,0,1,1,0,0, 0,0,1,1,1,0,0,1,0,0,0, 0,0,1,1,1,0,0,0,0,0,0, 0,0,1,1,0,0,0,0,0,0,0, 0,0,1,0,0,0,0,0,0,0,0, 0,0,0,1,0,0,0,0,0,0,0, 0,1,1,1,1,0,0,1,1,1,0, 0,1,1,1,1,0,0,1,1,0,0, 0,1,1,1,1,0,0,1,0,0,0, 0,1,1,1,1,0,0,0,0,0,0, 0,1,1,1,0,0,0,0,0,0,0, 0,1,1,0,0,0,0,0,0,0,0, }; int num[11], hash[255]; bool state[11]; void solve(char *data) { memset(num, 0, sizeof(num)); memset(state, 0, sizeof(state)); int l = strlen(data), t; for(int i = 0; i < l; i++) { t = hash[data[i]]; for(int j = 1; j < 11; j++) { if(table[t][j] && !state[j]) num[j]++, state[j] = 1; if(!table[t][j]) state[j] = 0; } } for(int i = 1; i < 11; i++) { printf("%d", num[i]); if(i == 10) printf("\n"); else printf(" "); } } int main() { int t; char data[205]; hash['c'] = 0, hash['d'] = 1, hash['e'] = 2; hash['f'] = 3, hash['g'] = 4, hash['a'] = 5; hash['b'] = 6, hash['C'] = 7, hash['D'] = 8; hash['E'] = 9, hash['F'] = 10, hash['G'] = 11; hash['A'] = 12, hash['B'] = 13; scanf("%d", &t); gets(data); while(t--) { gets(data); solve(data); } return 0; }
|
![]() |
|
Copyright © Fucker | Powered by: 博客園 模板提供:滬江博客 |