UCF Local Programming Contest 2012(Practice)
Posted wsxmmfby-jy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UCF Local Programming Contest 2012(Practice)相关的知识,希望对你有一定的参考价值。
B和H是两个水题C题是个模拟题,按照题目意思模拟就可以,只不过需要注意输出格式(指数行和底数行不能同时出现数字),G题也是个模拟题,题意是给出一个字符串,问能不能由上面那两个替换公式经过有限次替换得到,类似模拟括号匹配中栈的操作,不同的是不能出现紧挨的‘ab‘(可以是‘ba‘)。
//H #include <iostream> #include <algorithm> using namespace std; typedef long long ll; int main() { int n; cin >> n; int i=1; ll a[5]; for(int i=1;i<=n;i++) { for(int j=0;j<3;j++) { cin >> a[j]; } printf("Data set #%d: ",i); printf(" Original order: %lld %lld %lld ",a[0],a[1],a[2]); sort(a,a+3); printf(" Smallest to largest: %lld %lld %lld ",a[0],a[1],a[2]); printf(" "); } return 0; } //B #include <bits/stdc++.h> using namespace std; typedef long long ll; string s[3]; int main() { int t; cin >> t; string a,b; s[0]="First string is older"; s[1]="First string is younger"; s[2] = "The two strings are the same age"; cout << s[0]<<endl; for(int i=1;i<=t;i++) { cin >> a >> b; ll p[26]={0},q[26]={0}; for(int j=0;j<a.length();j++) { p[a[j]-‘a‘]++; } for(int j=0;j<b.length();j++) { q[b[j]-‘a‘]++; } int flag =0 ,bgm =0; for(int j=25;j>=0;j--) { if(p[j]>q[j]) { flag=1; break; } else if(p[j]<q[j]) { bgm =1; break; } } printf("Data set #%d: ",i); if(flag) { cout<<s[0]<<endl; } else if(bgm) { cout<<s[1]<<endl; } else{ cout<<s[2]<<endl; } printf(" "); } } //c #include <bits/stdc++.h> using namespace std; typedef long long ll; vector<pair<int,int>>v; const int N = 1e4 +10; struct node{ ll p,q; }; map<int,int>mp; node nd[N]; int kg1[N],kg2[N]; bool cmp(node x, node y) { return x.p<y.p; } int main() { int n; cin >> n; for(int i=1;i<=n;i++) { memset(kg2,0,sizeof(kg2)); memset(kg1,0,sizeof(kg1)); memset(nd,0,sizeof(nd)); mp.clear(); int m; cin >> m; int cun =1; for(int j=1;j<=m;j++) { int a,b; scanf("%d%d",&a,&b); if(mp[a]>0) { nd[mp[a]].q+=b; } else{ mp[a] = cun; nd[cun].p = a; nd[cun].q = b; cun++; } } sort(nd,nd+cun,cmp); printf("Prime Factorization #%d: ",i); for(int j=1;j<cun;j++) { int xy =nd[j].q; int num =0; while(xy) { xy/=10; num++; } kg1[j]=num; //printf(" %lld",nd[j].q); } //printf(" "); for(int j=1;j<cun;j++) { int xy =nd[j].p; int num =0; while(xy) { xy/=10; num++; } kg2[j]=num; //printf("%lld%c",nd[j].p,j+1==cun?‘ ‘:‘ ‘); } for(int j=1;j<cun;j++) { for(int k=1;k<=kg2[j];k++) { printf(" "); } printf("%lld",nd[j].q); } printf(" "); for(int j=1;j<cun;j++) { printf("%lld",nd[j].p); for(int k=1;k<=kg1[j];k++) { printf(" "); } } printf(" "); if(i!=n) printf(" "); } return 0; }
//G
#include<bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false); typedef long long ll; #define P 3.14159265358979 const int maxn=2e5+10; ll a[maxn],dp[maxn]; map<char,int>mp; int main(){ int t ; cin >> t; int sum=0; int tt=t; while(t--){ sum++; string s; cin >> s; cout << "Pattern "<< sum<<": "; stack<int> st; int vis[100]; memset(vis,0,sizeof(vis)); int len=s.length(); int aa[100],bb[100]; int cnta=0,cntb=0; int flag=0; for(int i=0;i<len;i++){ if(s[i]==‘a‘){ aa[++cnta]=i; continue; } if(s[i]==‘b‘){ bb[++cntb]=i; continue; } if(s[i]==‘c‘) continue; flag=1; } // cout << cnta << " " << cntb << endl; if(flag||(cnta!=cntb)) { cout<< "Still Looking." << endl; if(sum!=tt) cout << endl; continue; } int flag2=0; for(int i=0;i<len;i++){ if(s[i]==‘c‘) continue; if(s[i]==‘a‘) st.push(i); if(s[i]==‘b‘){ int flag3=0; int t=st.top(); for(int j=t+1;j<i;j++){ if(vis[j]==3) flag3=1; if(s[j]==‘c‘) flag3=1; } if(flag3==1){ for(int j=t;j<=i;j++){ vis[j]=3; } st.pop(); } else{ flag2=1; break; } } } if(flag2==1) cout<< "Still Looking." << endl; else cout << "More aliens!" << endl; if(sum!=tt) cout << endl; } return 0; }
以上是关于UCF Local Programming Contest 2012(Practice)的主要内容,如果未能解决你的问题,请参考以下文章
UCF Local Programming Contest 2017(2020-04-06)
UCF Local Programming Contest 2012(Practice)补题
UCF Local Programming Contest 2016正式赛
UCF Local Programming Contest 2016 3.29