标签:for dict station min front 坑点 数字 涂鸦 一个
A
注意格式,没啥坑点,重点是格式
对称输出对角线啊
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 typedef long long ll; 5 char mp[150][150]; 6 int main() 7 { 8 9 int n,num=1; 10 while(cin >> n&&n) 11 { 12 for(int i=1;i<=n;i++) 13 { 14 for(int j=1;j<=n;j++) 15 { 16 cin>> mp[i][j]; 17 } 18 } 19 printf("Input matrix #%d:\n",num);num++; 20 for(int i=1;i<=n;i++) 21 { 22 for(int j=1;j<=n;j++) 23 { 24 printf("%c%c",mp[i][j],(j==n?‘\n‘:‘ ‘)); 25 } 26 } 27 int k; 28 cin >>k; 29 while(k--) 30 { 31 int m; 32 cin >> m; 33 printf("Symmetric diagonals %d:\n",m); 34 int i = 1; 35 int j =m; 36 for(int k = j;k<=n;i++,k++) 37 { 38 printf("%c%c",mp[i][k],(k==n?‘\n‘:‘ ‘)); 39 } 40 int ii = m; 41 int jj =1; 42 if(m==1)continue; 43 for(int p = ii;p<=n;p++,jj++) 44 { 45 printf("%c%c",mp[p][jj],(p==n?‘\n‘:‘ ‘)); 46 } 47 }cout<<endl; 48 } 49 return 0; 50 }
B
注意格式,没啥坑点
就是个蛇形矩阵输出
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 typedef long long ll; 5 int mp[110][110]; 6 char mmp[110][110]; 7 int dx[]={1,0,-1,0}; 8 int dy[]={0,1,0,-1}; 9 int main() 10 { 11 int n,m,k=1; 12 while(~scanf("%d%d",&n,&m)) 13 { 14 memset(mp,0,sizeof(mp)); 15 if(n==0&&m==0)break; 16 for(int i=1;i<=n;i++) 17 { 18 for(int j=1;j<=m;j++) 19 { 20 cin>>mmp[i][j]; 21 } 22 } 23 printf("Matrix #%d:\n",k); 24 k++; 25 printf("Original:\n"); 26 for(int i=1;i<=n;i++) 27 { 28 for(int j=1;j<=m;j++) 29 { 30 printf("%c%c",mmp[i][j],(j==m?‘\n‘:‘ ‘)); 31 } 32 } 33 printf("Snail:\n"); 34 int num =0; 35 int fl=0; 36 int i=1,j=1; 37 while(num<n*m) 38 { 39 while(i<=n&&j<=m&&i>=1&&j>=1) 40 { 41 if(mp[i][j])break; 42 printf("%c",mmp[i][j]); 43 mp[i][j]=1; 44 i+=dy[fl]; 45 j+=dx[fl]; 46 //fl++; 47 num++; 48 } 49 i-=dy[fl]; 50 j-=dx[fl]; 51 //cout<<"egrebg4wgt"<<endl; 52 cout<<endl; 53 fl++; 54 fl%=4; 55 j+=dx[fl]; 56 i+=dy[fl]; 57 } 58 cout<<endl; 59 } 60 return 0; 61 }
C
三个价格,ord,plus,sup,这里面ord<plus<sup,数字被涂污,题目保证符合题意的存在,且每个数都是由三个字符组成
因为第一个数不能是0,1,因此在这个地方需要注意下,把涂鸦的地方尽可能选最小的对于ord
当然plus要大于ord,因此需要简单判断总共三个字符暴力解决
对于sup,同样的操作
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn=1e5+10; 5 6 char ch[100][100]; 7 8 int num[100]; 9 10 string str1,str2,str3; 11 12 string chack(string s1,string s2){ 13 if(s2[0] == ‘-‘){ 14 if((s2[1] > s1[1]) ||(s2[1] == s1[1] && s2[2] > s1[2])) 15 s2[0] = s1[0]; 16 else 17 s2[0] = s1[0] + 1; 18 // cout << 1 << endl; 19 } 20 else if(s2[1] == ‘-‘){ 21 if(s2[0] <= s1[0]){ 22 if(s2[2] > s1[2]) 23 s2[1] = s1[1]; 24 else 25 s2[1] = s1[1] + 1; 26 } 27 else{ 28 s2[1] = ‘0‘; 29 } 30 } 31 else if(s2[2] == ‘-‘){ 32 if(s2[0] > s1[0] || s2[1] > s1[1]) 33 s2[2] = ‘0‘; 34 else 35 s2[2] = s1[2] + 1; 36 } 37 return s2; 38 } 39 40 int main(){ 41 int n; 42 while(cin >> n){ 43 for(int i = 1;i <= n;i++){ 44 cin >> str1 >> str2 >> str3; 45 printf("Gas Station #%d:\n",i); 46 cout << " Input: " << str1 << ‘ ‘ << str2 << ‘ ‘ << str3 << endl; 47 for(int i = 0;i < 3;i++){ 48 if(str1[i] == ‘-‘ && i == 0) 49 str1[i] = ‘2‘; 50 else if(str1[i] == ‘-‘ && i != 0) 51 str1[i] = ‘0‘; 52 } 53 str2 = chack(str1,str2); 54 str3 = chack(str2,str3); 55 cout << " Output: " << str1 << ‘ ‘ << str2 << ‘ ‘ << str3 << endl; 56 cout << endl; 57 } 58 } 59 return 0; 60 }
H
裸的bfs,就是bfs的入门题目,
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 typedef long long ll; 6 struct node{ 7 int i,j,val; 8 }; 9 queue<node>q; 10 int mp[40][40]={0}; 11 int mmp[40][40]={0}; 12 int n; 13 int x,y; 14 int dx[]={2,1,-2,-1,2,1,-2,-1}; 15 int dy[]={1,2,-1,-2,-1,-2,1,2}; 16 int r,c; 17 void bfs(int x,int y) 18 { 19 memset(mp,-1,sizeof(mp)); 20 mp[x][y]=0; 21 mmp[x][y]=1; 22 q.push(node{x,y,0}); 23 while(!q.empty()) 24 { 25 node u = q.front(); 26 q.pop(); 27 for(int i=0;i<8;i++) 28 { 29 node v = node{u.i+dx[i],u.j+dy[i],u.val+1}; 30 if(v.i<=n&&v.j<=n&&v.i>0&&v.j>0&&mmp[v.i][v.j]==0) 31 { 32 mp[v.i][v.j]=v.val; 33 mmp[v.i][v.j]=1; 34 q.push(v); 35 } 36 } 37 } 38 } 39 int main() 40 { 41 int t; 42 cin >> t; 43 for(int i=1;i<=t;i++) 44 { 45 memset(mp,0,sizeof(mp)); 46 memset(mmp,0,sizeof(mmp)); 47 cin >> n >> x >> y>> r>> c; 48 bfs(x,y); 49 printf("Case #%d: %d\n",i,mp[r][c]); 50 cout<<endl; 51 } 52 53 return 0; 54 }
D题
给你一个词典,接下来是n个单词查询是不是在字典中,或者有多个单词拼接,或者没有
当时我是暴力写的,觉得没有什么地方不妥,现在一只都不明白错在哪
代码贴上,有巨巨看到那个地方有问题,恳求指正,在线发抖
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 typedef long long ll; 5 string dic[60]; 6 vector<int>v[26]; 7 int main() 8 { 9 int n; 10 int kk=1; 11 while(~scanf("%d",&n)&&n) 12 { 13 for(int i=1;i<=n;i++) 14 { 15 cin >> dic[i]; 16 v[dic[i][0]-‘a‘].push_back(i); 17 } 18 int m; 19 cin >> m; 20 printf("Data set #%d:\n",kk);kk++; 21 while(m--) 22 { 23 string s; 24 cin >> s; 25 int tb=0; 26 for(int i=1;i<=n;i++) 27 { 28 if(s==dic[i]) 29 { 30 printf(" "); 31 cout<< s; 32 printf(" --- the word is in dictionary\n"); 33 tb=1; 34 break; 35 } 36 37 } 38 if(tb==1)continue; 39 int i=0; 40 int blg=0; 41 int num =0; 42 vector<int>c; 43 while(i<s.length()) 44 { 45 int flag=0; 46 for(int j=0;j<v[s[i]-‘a‘].size();j++) 47 { 48 int p = v[s[i]-‘a‘][j]; 49 50 string ss = dic[p]; 51 52 int len = ss.length(); 53 string st; 54 for(int k = 0;k<ss.length();k++) 55 { 56 st+=s[i+k]; 57 } 58 59 if(st==ss) 60 { 61 flag=1; 62 num++; 63 i+=ss.length(); 64 c.push_back(p); 65 break; 66 } 67 } 68 if(flag==0) 69 { 70 blg=1; 71 break; 72 } 73 } 74 if(blg) 75 { 76 printf(" "); 77 cout<< s; 78 printf(" --- misspelled word\n"); 79 } 80 else{ 81 if(num>1) 82 { 83 printf(" "); 84 cout<< s; 85 printf(" --- the word is concatenation of\n"); 86 for(int i=0;i<c.size();i++) 87 { 88 printf(" "); 89 cout<<dic[c[i]]<<endl; 90 } 91 } 92 else{ 93 printf(" "); 94 cout<< s; 95 printf(" --- the word is in dictionary\n"); 96 } 97 } 98 } 99 for(int i=0;i<26;i++)v[i].clear(); 100 cout<<endl; 101 } 102 return 0; 103 }
题目的正解官方答案是字典树,哈哈哈,我太菜了,目前还不会,等我学完回来更新,瑟瑟发抖!!!!
UCF Local Programming Contest 2015(Practice)个人分析
标签:for dict station min front 坑点 数字 涂鸦 一个
原文地址:https://www.cnblogs.com/wsxmmfby-jy/p/12759549.html