ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Codeforces Round #713

2021-04-11 08:32:24  阅读:147  来源: 互联网

标签:bi int LL 713 Codeforces cin sum include Round


又是该LL用int了,什么时候才能不犯病啊。

A:水题,让你找出3个以上的数组中不同的那个数

  我是直接分情况。

 1 #include<iostream>
 2 #include<vector>
 3 using namespace std;
 4 const int N=110;
 5 int a[N];
 6 int main(void){
 7     int t;
 8     cin>>t;
 9     while(t--){
10         int n;
11         cin>>n;
12         for(int i=1;i<=n;i++){
13             cin>>a[i];
14         }
15         int t=a[1];
16         for(int i=2;i<=n;i++){
17             if(a[i]!=t){
18                 if(i==2){
19                     if(a[2]==a[3]){
20                         cout<<1<<endl;
21                     }else{
22                         cout<<2<<endl;
23                     }
24                 }else{
25                     cout<<i<<endl;
26                 }
27                 break;
28             }
29         }
30     }
31     return 0;
32 }

 

 

B:给你一个带两个*的矩阵,输出带四个*的矩阵,其中4个*组成一个矩形。

  保证a在b的上面,直接分成四种情况。

 1 #include<iostream>
 2 #include<vector>
 3 #define x first
 4 #define y second
 5 using namespace std;
 6 const int N=500;
 7 char s[N][N];
 8 int main(void){
 9     int t;
10     cin>>t;
11     while(t--){
12         int n;
13         cin>>n;
14         for(int i=0;i<n;i++) cin>>s[i];
15         pair<int,int> a,b;
16         int cnt=0;
17         for(int i=0;i<n;i++)
18             for(int j=0;j<n;j++)
19                 if(s[i][j]=='*'){
20                     if(cnt==0)
21                         a={i,j},cnt++;
22                     else
23                         b={i,j};
24                 }
25         if(a.x>b.x) swap(a,b);
26         if(a.x!=b.x&&a.y!=b.y){
27             s[a.x][b.y]='*';
28             s[b.x][a.y]='*';
29         }else if(a.x==b.x){
30             if(a.x==0){
31                 s[n-1][a.y]='*';
32                 s[n-1][b.y]='*';
33             }else{
34                 s[0][a.y]='*';
35                 s[0][b.y]='*';
36             }
37         }else if(a.y==b.y){
38             if(a.y==0){
39                 s[a.x][n-1]='*';
40                 s[b.x][n-1]='*';
41             }else{
42                 s[a.x][0]='*';
43                 s[b.x][0]='*';
44             }
45         }
46         for(int i=0;i<n;i++){
47             for(int j=0;j<n;j++)
48                 cout<<s[i][j];
49             cout<<endl;
50         }
51     }
52  
53     return 0;
54 }

 

C:待补充。

 

D:sum代表全部的和,sum=2(a1+...+an)+x

  枚举每一个bi,假设他是x,然后找是否存在一个不等于 i 的 (sum-bi)/2 的值

  若存在则bi等于x,找到的数等于a[n+1]

  找不等于i的(sum-bi)/2的值是因为一个数不能既是x又是b[n+1]

 1 #include<iostream>
 2 #include<vector>
 3 #include<map>
 4 using namespace std;
 5 typedef long long LL;
 6 const LL N=2e5+10;
 7 LL a[N];
 8 int main(void){
 9     LL t;
10     cin>>t;
11     while(t--){
12         LL sum=0;
13         LL n;
14         cin>>n;
15         map<LL,LL> mp;
16         for(LL i=1;i<=n+2;i++){
17             cin>>a[i];
18             mp[a[i]]++;
19             sum+=a[i];
20         }
21         LL t1=-1,t2=-1;
22         for(LL i=1;i<=n+2;i++){
23             LL tmp=sum-a[i];
24             if(tmp%2==0&&((mp[tmp/2]==1&&a[i]!=tmp/2)||mp[tmp/2]>=2)){
25                 t1=a[i],t2=tmp/2;
26             }
27         }
28         if(t1==-1&&t2==-1){
29             cout<<-1<<endl;
30         }else{
31             for(LL i=1;i<=n+2;i++){
32                 if(a[i]==t1){
33                     t1=-1;
34                     continue;
35                 }
36                 if(a[i]==t2){
37                     t2=-1;
38                     continue;
39                 }
40                 cout<<a[i]<<" ";
41             }
42             cout<<endl;
43         }
44     }
45     return 0 ;
46 }

 

标签:bi,int,LL,713,Codeforces,cin,sum,include,Round
来源: https://www.cnblogs.com/greenofyu/p/14642914.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有