2015年江西理工大学C语言程序设计竞赛(初级组)
JankTao相亲记
解法:排序
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 | #include<stdio.h> #include<string.h> #include<iostream> #include<math.h> #include<map> #include<set> #include<vector> #include<algorithm> using namespace std; const double INF = 1e20; const double pi = acos (-1.); int main() { int t; int a[100]; while (cin>>t) { while (t--) { for ( int i=0;i<11;i++) { cin>>a[i]; } sort(a,a+11); printf ( "%d\n" ,a[9]); } } return 0; } |
David的沙漠之路
解法:贪心,尽量往最大的距离走,加上它经历过的加油站中最大的那个,模拟这个过程需要考虑很多情况
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #include <iostream> #include <stdio.h> #include <queue> using namespace std; struct cmp { bool operator ()( int &a, int &b) { return a<b; } }; struct node { int x,y; } e[1005]; int main() { priority_queue< int ,vector< int >,cmp>que; int T; scanf ( "%d" ,&T); while (T--) { int n,l,s,x,y,cnt=0,flag=0,f=0; scanf ( "%d%d%d" ,&n,&l,&s); for ( int i=0; i<n; i++) { scanf ( "%d%d" ,&e[i].x,&e[i].y); } e[n].x=0,e[n].y=l; for ( int i=0; i<=n; i++,f=0) { x=e[i].x,y=e[i].y; if (y<=s) { que.push(x); f=1; //最长可以横跨多少加油站,把他们放在队列里 } while (y>=s) { if (s>=l) break ; if (!f && s==y) { que.push(x); f=1; //没有横跨,刚刚好到达 } if (que.empty()) { printf ( "TJ\n" ); flag=1; break ; } int xx=que.top(); //取最近的加油站 que.pop(); s+=xx; cnt++; } if (!f) que.push(x); if (s>=l) { printf ( "%d\n" ,cnt); flag=1; break ; } if (flag) break ; } if (!flag) printf ( "TJ\n" ); while (!que.empty()) que.pop(); } return 0; } |
TJ的文件系统
解法:字符串处理
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include<stdio.h> //#include<bits/stdc++.h> #include<string.h> #include<iostream> #include<math.h> #include<sstream> #include<set> #include<queue> #include<vector> #include<algorithm> #include<limits.h> #define inf 0x3fffffff #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long using namespace std; const int maxn = 22; int main() { int t; int n; int i; int j; string s,ss; while (cin>>t) { while (t--) { string sss= "" ; int ans; cin>>n>>s; for (i=0;i<n;i++) { string sss= "" ; cin>>ss; ans=ss.find( "." ); // cout<<ans<<endl; for (j=ans+1;j<ss.length();j++) { sss+=ss[j]; } // cout<<sss<<endl; if (sss==s) { cout<<ss<<endl; } } } } return 0; } |
握手定理
解法:水题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <stdio.h> int main() { int SEQ, ACK1, ACK2, T; scanf ( "%d" , &T); while (T--) { scanf ( "%d %d %d" , &SEQ, &ACK1, &ACK2); if ((ACK1 == SEQ + 1) && (ACK2 == ACK1 + 1)) { printf ( "QWN3213\n" ); } else printf ( "TJ\n" ); } return 0; } |
Alice AND Bob
解法:模拟
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include<stdio.h> //#include<bits/stdc++.h> #include<string.h> #include<iostream> #include<math.h> #include<sstream> #include<set> #include<queue> #include<vector> #include<algorithm> #include<limits.h> #define inf 0x3fffffff #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long using namespace std; int a[100000],b[100000],c[100000]; int main() { int t; int i,j; int n,m; int x,y; int k; cin>>t; while (t--) { k=0; cin>>n>>m; memset (a,0, sizeof (a)); memset (b,0, sizeof (b)); for (i=0;i<n;i++) { cin>>x; a[x]++; } for (i=0;i<m;i++) { cin>>y; b[y]++; } for (i=0;i<100000;i++) { if (a[i]&&b[i]) c[k++]=i; } for (i=0;i<k;i++) { if (i==0) { printf ( "%d" ,c[i]); } else { printf ( " %d" ,c[i]); } } cout<<endl; } return 0; } |
建群数据
解法:字符串处理时间
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | #include<stdio.h> //#include<bits/stdc++.h> #include<string.h> #include<iostream> #include<math.h> #include<sstream> #include<set> #include<queue> #include<vector> #include<algorithm> #include<limits.h> #define inf 0x3fffffff #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long using namespace std; struct P { int number; int hhmmss; }hehe[100000]; int cmp(P a,P b) { if (a.number==b.number) return a.hhmmss<b.hhmmss; else return a.number<b.number; } string s,ss,sss,ssss; string sssss; int t,n; int a; int i,j; int ans; int poi; int num; int main() { cin>>t; while (t--) { poi=1; cin>>n; for (i=0;i<n;i++) { cin>>a>>s; hehe[i].number=a; ss=s.substr(0,2); sss=s.substr(2,2); ssss=s.substr(4,2); // cout<<ss<<" "<<sss<<" "<<ssss<<endl; hehe[i].hhmmss=((ss[0]- '0' )*10+(ss[1]- '0' )*1)*3600+((sss[0]- '0' )*10+(sss[1]- '0' ))*60+((ssss[0]- '0' )*10+(ssss[1]- '0' )); } cin>>sssss; ss=sssss.substr(0,2); sss=sssss.substr(2,2); ssss=sssss.substr(4,2); ans=((ss[0]- '0' )*10+(ss[1]- '0' ))*3600+((sss[0]- '0' )*10+(sss[1]- '0' ))*60+((ssss[0]- '0' )*10+(ssss[1]- '0' )); sort(hehe,hehe+n,cmp); num=hehe[0].hhmmss; for ( int i=1;i<n;i++) { if (hehe[i].number!= hehe[i-1].number||hehe[i].hhmmss-num>ans) { poi++; num=hehe[i].hhmmss; } } printf ( "%d\n" ,poi); } return 0; } |
分类:
某些比赛
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~