zoukankan      html  css  js  c++  java
  • Codeforces Round #713

    又是该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 }
  • 相关阅读:
    单表查询
    解读python中SocketServer源码
    C++实训(2.3)
    C++实训(2.2)
    C++实训(2.1)
    C++实训(1.3)
    C++实训(1.1)
    顺序表的实现,在vs2019上运行成功
    p243_5(3)
    自考新教材-p176_5(2)
  • 原文地址:https://www.cnblogs.com/greenofyu/p/14642914.html
Copyright © 2011-2022 走看看