Codeforces Round #619 (Div. 2)

A.Three Strings

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int N = 1e5 + 7;
 5 const int inf = 0x3f3f3f3f;
 6 char a[110],b[110],c[110];
 7 int t;
 8 int main()
 9 {
10     scanf("%d",&t);
11     while(t--)
12     {
13         scanf("%s%s%s",a,b,c);
14         int len=strlen(a);
15         bool ok=false;
16         for(int i=0;i<len;i++)
17         {
18             if(a[i]==c[i]||b[i]==c[i]) continue;
19             ok=true;
20         }
21         if(ok) puts("NO");
22         else puts("YES");
23     }
24     return 0;
25 }
View Code

B. Motarack's Birthday

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int N = 1e5 + 7;
 5 const int inf = 0x3f3f3f3f;
 6 int a[N];
 7 int t,n;
 8 void work(int a[])
 9 {
10     bool ok=true;
11     int maxx=0,minx=inf;
12     int res=0;
13     for(int i=1;i<=n;i++)
14     {
15         if(a[i]!=-1)
16         {
17             ok=false;
18             if(a[i-1]!=-1) res=max(res,abs(a[i]-a[i-1]));
19             if(a[i+1]!=-1) res=max(res,abs(a[i]-a[i+1]));
20             continue;
21         }
22         if(a[i-1]!=-1) maxx=max(maxx,a[i-1]),minx=min(minx,a[i-1]);
23         if(a[i+1]!=-1) maxx=max(maxx,a[i+1]),minx=min(minx,a[i+1]);
24     }
25     if(ok)
26     {
27         cout<<0<<" "<<1<<endl;
28  
29     }
30     else
31     {
32         int k = (maxx+minx+1)/2;
33         cout<<max(res,max(abs(maxx-k),abs(minx-k)))<<" "<<k<<'
';
34     }
35 }
36 int main()
37 {
38     scanf("%d",&t);
39     while(t--)
40     {
41         scanf("%d",&n);
42         for(int i=1;i<=n;i++) scanf("%d",&a[i]);
43         a[0]=-1, a[n+1]=-1;
44         work(a);
45     }
46     return 0;
47 }
View Code

C. Ayoub's function

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int N = 1e5 + 7;
 5 const int inf = 0x3f3f3f3f;
 6 int T;
 7 ll n,m;
 8 void work(ll n, ll m)
 9 {
10     ll ans=(n+1)*n/2;
11     ll d=n-m;
12     ll x=d/(m+1);
13     ll y=d%(m+1);
14     ll cnt=m-y+1;
15     ans-=cnt*(x*(x+1)/2);
16     ans-=y*((x+2)*(x+1)/2);
17     cout<<ans<<'
';
18 }
19 int main()
20 {
21     scanf("%d",&T);
22     while(T--)
23     {
24         cin>>n>>m;
25         work(n,m);
26     }
27     return 0;
28 }
View Code
原文地址:https://www.cnblogs.com/Edviv/p/12308037.html