Article From:https://www.cnblogs.com/HDUjackyan/p/9063722.html

B.http://codeforces.com/contest/579/problem/B

Meaning: there are n teams, 2n individuals, and then 2N-1 lines, line I (in the input of the i+1 line), the j column indicates the score that the I individual and the j individual team can get, each person wants their own scores to be as high as possible, and the output of each person and the team.

Analysis: the input into the structure, the structure contains variables X, y, D, X and y to represent the team of two people, D to show the score obtained by the team, according to the score from large to small to sort, and constantly determine the formation of the team situation

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 using namespace std;
 6 const int maxn=810;
 7 struct node{
 8     int x,y,d;
 9 }arr[maxn*maxn];
10 int belong[maxn];
11 
12 bool cmp(node a,node b)
13 {
14     return a.d>b.d;
15 }
16 
17 int main()
18 {
19     int i,j,k,n,cnt;
20     while ( scanf("%d",&n)!=EOF )
21     {
22         memset(belong,0,sizeof(belong));
23         cnt=0;
24         for ( i=2;i<=2*n;i++ )
25             for ( j=1;j<i;j++ )
26             {
27                 scanf("%d",&arr[++cnt].d);
28                 arr[cnt].x=i;
29                 arr[cnt].y=j;
30             }
31         sort(arr+1,arr+1+cnt,cmp);
32         for ( i=1;i<=cnt;i++ )
33         {
34             if ( belong[arr[i].x] || belong[arr[i].y] ) continue;
35             else {
36                 belong[arr[i].x]=arr[i].y;
37                 belong[arr[i].y]=arr[i].x;
38             }
39         }
40         for ( i=1;i<=2*n;i++ )
41         {
42             printf("%d",belong[i]);
43             if ( i!=2*n ) printf(" ");
44             else printf("\n");
45         }
46     }
47     return 0;
48 }

579B

 

C.http://codeforces.com/contest/579/problem/C

Meaning: give a point(0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – … - (2kx, 0) – (2kx + x, x) – ….The broken line, then give the point (a, b). What is the minimum of X in the broken line of the point (a, b)? If there is no broken line (a, b), the output -1. The answer is exactly 9 in the decimal point.

Analysis: mathematics. According to the meaning, the slopes of all straight lines in the graph are 1 or -1. And when (a, b) is on the straight line of k=1, (a, b) the former point is (A-B, 0); when (a, b) is on the straight line of k=-1, (a, b) the next point is (F, 0). becauseThe parity of a+b and A-B is the same. Choose one consideration. We consider (a+b, 0) this point, assuming that there is a 2p X in [0 and a+b], then we have x= (a+b) /2p& & x> =b, combined with the two formula can be obtained first.The largest P then pushes the X. Pay attention to b/a&gt, 1, there is no solution, output -1.

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 using namespace std;
 6 const double eps=1e-9;
 7 
 8 int main()
 9 {
10     int a,b,i,j,x1,x2,p;
11     double k,ans,l,r,mid;
12     while ( scanf("%d%d",&a,&b)!=EOF )
13     {
14         k=(double)1.0*b/a;
15         if ( k-1>eps )
16         {
17             printf("-1\n");
18             continue;
19         }
20         x1=a-b;
21         x2=a+b;
22         p=x2/(2*b);
23         ans=(double)(1.0*x2/(2*p));
24         printf("%.9lf\n",ans);
25     }
26     return 0;
27 }

579C

 

D.http://codeforces.com/contest/579/problem/D

Meaning: give the number of N, there is a maximum of K operation, each operation can make a number of X, and finally the number of N or operation to get the maximum and how much

Analysis: because or operation, so that the highest position as high as possible, so the K times multiplication operations are carried out on a number. So enumerating each number for K operations, there is a trick: maintaining the sum of the front suffix, so that it can be conveniently calculated.

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 using namespace std;
 6 typedef long long ll;
 7 const int maxn=2e5+10;
 8 ll a[maxn],b[maxn],c[maxn];
 9 
10 int main()
11 {
12     ll n,k,x,i,j,ans,now,add;
13     while ( scanf("%lld%lld%lld",&n,&k,&x)!=EOF )
14     {
15         add=pow(x,k);
16         memset(a,0,sizeof(a));
17         memset(b,0,sizeof(b));
18         for ( i=1;i<=n;i++ ) 
19         {
20             scanf("%lld",&c[i]);
21             a[i]=a[i-1]|c[i];
22         }
23         for ( i=n;i>0;i-- ) b[i]=b[i+1]|c[i];
24         ans=0;
25         for ( i=1;i<=n;i++ )
26         {
27             now=(c[i]*add)|a[i-1]|b[i+1];
28             ans=max(ans,now);
29         }
30         printf("%lld\n",ans);
31     }
32     return 0;
33 }

579D

 

Similar Posts:

Link of this Article: Codeforces Round #320 (Div. 2)

Leave a Reply

Your email address will not be published. Required fields are marked *