西南民族大学第十届校赛(同步赛)

可AK场,题目非常基础,可惜比赛时太困,没来得及AK...由于一开始选了C++14,导致写B题时用gets函数一直编译报错,用getline就一直T到飞...赛后改C++11就过了,最终没来得及看非常easy的J题QAQ~

A.dreamstart的催促:签道题。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const LL mod=10000019;
 5 const int maxn=1e5+5;
 6 int n;LL ans,x;
 7 LL quick_mod(LL a,LL b){
 8     LL res=1LL;
 9     while(b){
10         if(b&1)res=res*a%mod;
11         a=a*a%mod;
12         b>>=1;
13     }
14     return res;
15 }
16 int main(){
17     while(~scanf("%d",&n)){
18         ans=0;
19         for(int i=1;i<=n;++i)scanf("%lld",&x),ans=(ans+quick_mod(x,i))%mod;
20         printf("%lld\n",ans);
21     }
22     return 0;
23 }
View Code

B.TRDD got lost again:基础的bfs,注意读入的方式。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int maxn=6005;
 5 int n,m,a,b,sx,sy;char mp[maxn][maxn],mo[maxn];bool vis[maxn][maxn];
 6 int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};///上下,左右
 7 struct node{int x,y,step;}nod,tmp;
 8 queue<node> que;
 9 int bfs(int x,int y){
10     while(!que.empty())que.pop();
11     vis[nod.x=x][nod.y=y]=true,nod.step=1;
12     que.push(nod);
13     while(!que.empty()){
14         nod=que.front(),que.pop();
15         int nx=nod.x,ny=nod.y,nstep=nod.step;
16         if(mp[nx][ny]=='T')return nstep+1;
17         for(int i=0;i<2;++i){///上下
18             int gx=nx+dir[i][0],gy=ny+dir[i][1],gstep=nstep+1;
19             if(gx>=0&&gx<a&&gy>=0&&gy<b&&!vis[gx][gy]&&mp[gx][gy]!='-'&&mp[gx][gy]!='+'){
20                 tmp.x=gx,tmp.y=gy,tmp.step=gstep,vis[gx][gy]=true;
21                 que.push(tmp);
22             }
23         }
24         for(int i=2;i<4;++i){///左右
25             int gx=nx+dir[i][0],gy=ny+dir[i][1],gstep=nstep+1;
26             if(gx>=0&&gx<a&&gy>=0&&gy<b&&!vis[gx][gy]&&mp[gx][gy]!='|'&&mp[gx][gy]!='+'){
27                 tmp.x=gx,tmp.y=gy,tmp.step=gstep,vis[gx][gy]=true;
28                 que.push(tmp);
29             }
30         }
31     }
32     return -1;
33 }
34 int main(){
35     while(~scanf("%d%d",&n,&m)){
36         a=2*n+1,b=2*m+1;getchar();///注意读走回车符
37         memset(vis,false,sizeof(vis));
38         for(int i=0;i<a;++i)gets(mp[i]);
39         for(int i=0;i<n;++i){
40             for(int j=0;j<m;++j){
41                 if(mp[2*i+1][2*j+1]=='S'){sx=2*i+1,sy=2*j+1;break;}
42             }
43         }
44         int ans=bfs(sx,sy);
45         if(ans!=-1)printf("%d\n",ans/2);
46         else puts("TRDD Got lost...TAT");
47     }
48     return 0;
49 }
View Code

C.Company:先预处理一下每个节点的权值,再dfs跑一下即可。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int maxn=200005;
 5 int n,k,x,u,v,w[maxn];vector<int> vec[maxn];
 6 void dfs(int now,int per){
 7     for(size_t i=0;i<vec[now].size();++i){
 8         if(per^vec[now][i]){
 9             dfs(vec[now][i],now);
10             w[now]+=w[vec[now][i]];
11         }
12     }
13 }
14 int main(){
15     while(cin>>n>>k){
16         for(int i=1;i<=n;++i)cin>>x,w[i]=x>k?0:1,vec[i].clear();
17         for(int i=1;i<n;++i){
18             cin>>u>>v;
19             vec[u].push_back(v);
20             vec[v].push_back(u);
21         }
22         dfs(1,0);
23         for(int i=1;i<=n;++i)cout<<w[i]<<(i==n?'\n':' ');
24     }
25     return 0;
26 }
View Code

D.>A->B->C-:-_-三角恋。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const LL mod=10000019;
 5 const int maxn=5005;
 6 int n,love[maxn],b,c;bool flag;
 7 int main(){
 8     while(cin>>n){
 9         flag=false;memset(love,-1,sizeof(love));
10         for(int i=1;i<=n;++i)cin>>love[i];
11         for(int i=1;i<=n;++i){
12             b=love[i],c=love[b];
13             if(love[c]==i){flag=true;break;}
14         }
15         puts(flag?"YES":"NO");
16     }
17     return 0;
18 }
View Code

E.PPY的字符串:用字符串暴力模拟一下即可。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 int n,cnt;string per,now;char tmp;
 5 int main(){
 6     while(cin>>per>>n){
 7         for(int j=2;j<=n;++j){
 8             now="";
 9             for(int i=0;per[i];++i){
10                 cnt=0,tmp=per[i];
11                 while(per[i]&&tmp==per[i])i++,cnt++;
12                 now+=cnt+'0';
13                 now+=tmp;
14                 --i;
15             }
16             per=now;
17         }
18         cout<<per.size()<<' '<<per<<endl;
19     }
20     return 0;
21 }
View Code

F.集训队脱单大法:这是一道只能由学姐我自己出数据的水题:用优选队列最大堆维护当前序列的最大值,用set容器维护后面序列的最大值,扫一遍即可。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const LL mod=10000019;
 5 const int maxn=1e5+5;
 6 int n,a[maxn],ans;set<int> st;map<int,int> mp;set<int>::iterator it;
 7 priority_queue<int> que;
 8 int main(){
 9     while(cin>>n){
10         st.clear(),mp.clear();ans=0;
11         while(!que.empty())que.pop();
12         for(int i=0;i<n;++i)cin>>a[i],mp[a[i]]++,st.insert(a[i]);
13         for(int i=0;i<n-1;++i){
14             que.push(a[i]);
15             mp[a[i]]--;
16             if(!mp[a[i]])st.erase(a[i]);
17             it=st.end();--it;
18             ans=max(ans,abs(*it-que.top()));
19         }
20         cout<<ans<<endl;
21     }
22     return 0;
23 }
View Code

G.不想再WA了:入门dp。定义dp[i][0~2:0表示'A';1表示'C';2表示'W']表示当前组成长度为i且以字符j结尾的字符串方案数。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const LL mod=10000019;
 5 int n,T;LL dp[15][3],ans[15];
 6 int main(){
 7     memset(dp,0,sizeof(dp));
 8     memset(ans,0,sizeof(ans));
 9     dp[0][0]=1;
10     for(int i=1;i<=10;++i){
11         dp[i][0]+=dp[i-1][0]+dp[i-1][1];///A
12         dp[i][1]+=dp[i-1][0]+dp[i-1][1]+dp[i-1][2];///C
13         dp[i][2]+=dp[i-1][0]+dp[i-1][1]+dp[i-1][2];///w
14     }
15     for(int i=1;i<=10;++i)ans[i]=dp[i][0]+dp[i][1]+dp[i][2];///预处理答案
16     while(cin>>T){
17         while(T--){
18             cin>>n;
19             cout<<ans[n]<<endl;
20         }
21     }
22     return 0;
23 }
View Code

H.Ricky’s RealDan’s Ricky:简单博弈,模拟一下玩法可知当且仅当只有一个偶数时,先手必赢,其余情况后手必赢。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 int T,n,x,odd,even;
 5 int main(){
 6     while(cin>>T){
 7         while(T--){
 8             cin>>n,odd=even=0;
 9             for(int i=0;i<n;++i){
10                 cin>>x;
11                 if(x&1)odd++;
12                 else even++;
13             }
14             if(n==1&&even)puts("Ricky is Winner");
15             else puts("RealDan is Winner");
16         }
17     }
18     return 0;
19 }
View Code

I.小A的期末作业

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const LL mod=10000019;
 5 const int maxn=5005;
 6 int n;
 7 int main(){
 8     while(cin>>n){
 9         for(int i=1;i<=n;++i)printf("*");
10         puts("");
11         for(int i=1;i<n;++i){
12             for(int j=1;j<=i;++j)printf(" ");
13             for(int j=1;j<=n;++j)printf("*");
14             puts("");
15         }
16         for(int i=n-2;i>=0;--i){
17             for(int j=1;j<=i;++j)printf(" ");
18             for(int j=1;j<=n;++j)printf("*");
19             puts("");
20         }
21     }
22     return 0;
23 }
View Code

J.怪盗基德 & 月之瞳宝石:离散化处理,先对能源体的位置进行排序,对于每个星体,找最近的能源体,最后取个最大的距离即可。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int maxn=1e5+5;
 5 int n,m;LL a[maxn],b[maxn],ans,pos;
 6 int main(){
 7     while(cin>>n>>m){
 8         for(int i=0;i<n;++i)cin>>a[i];
 9         for(int i=0;i<m;++i)cin>>b[i];
10         sort(b,b+m);ans=0;
11         for(int i=0;i<n;++i){
12             pos=upper_bound(b,b+m,a[i])-b;
13             if(!pos)ans=max(ans,b[pos]-a[i]);
14             else if(pos==m)ans=max(ans,abs(a[i]-b[pos-1]));
15             else ans=max(ans,min(abs(b[pos]-a[i]),abs(a[i]-b[pos-1])));
16         }
17         cout<<ans<<endl;
18     }
19     return 0;
20 }
View Code

K.正方体:简单处理一下即可。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const LL mod=10000019;
 5 const int maxn=1e5+5;
 6 int T,x,mo[7],cnt,flag;
 7 int main(){
 8     while(cin>>T){
 9         flag=0;
10         while(T--){
11             memset(mo,0,sizeof(mo)),cnt=0;flag++;
12             for(int i=1;i<=4;++i){cin>>x;if(x!=0)mo[1]=x;}
13             for(int i=2;i<=5;++i)cin>>mo[i];
14             for(int i=1;i<=4;++i){cin>>x;if(x!=0)mo[6]=x;}
15             cnt+=(mo[1]==mo[6]);
16             cnt+=(mo[2]==mo[4]);
17             cnt+=(mo[3]==mo[5]);
18             if(cnt==3)puts("Yes!");
19             else puts("No!");
20             if(flag%50==0)puts("");
21         }
22     }
23     return 0;
24 }
View Code

L.简单的分数:常规写法。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const LL mod=10000019;
 5 const int maxn=5005;
 6 int T,op,a,b,c,d,ans1,ans2,tmp,flag;
 7 int gcd(int a,int b){return b?gcd(b,a%b):a;}
 8 int main(){
 9     while(cin>>T){
10         while(T--){
11             cin>>op>>a>>b>>c>>d;flag=0;
12             ans1=a*d+(!op?-1:1)*b*c;
13             ans2=b*d;
14             if(ans1<0)flag++,ans1*=-1;
15             if(ans2<0)flag++,ans2*=-1;
16             tmp=gcd(ans1,ans2);
17             ans1/=tmp,ans2/=tmp;
18             if(flag&1)printf("-");
19             printf("%d/%d\n",ans1,ans2);
20         }
21     }
22     return 0;
23 }
View Code

M.HJ浇花:差分标记,再暴力一下求前缀和即可。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const LL mod=10000019;
 5 const int maxn=1e6+5;
 6 int n,l,r,xfen[maxn];map<int,int> mp;
 7 int main(){
 8     while(cin>>n){
 9         memset(xfen,0,sizeof(xfen));
10         mp.clear();
11         for(int i=0;i<n;++i){
12             cin>>l>>r;
13             xfen[l]++,xfen[r+1]--;
14         }
15         mp[xfen[0]]++;
16         for(int i=1;i<=1000000;++i){
17             xfen[i]+=xfen[i-1];
18             mp[xfen[i]]++;
19         }
20         for(int i=1;i<=n;++i)cout<<mp[i]<<(i==n?'\n':' ');
21     }
22  
23     return 0;
24 }
View Code

猜你喜欢

转载自www.cnblogs.com/acgoto/p/10200525.html
今日推荐