June Challenge 2017

A Good Set

分析:水题,选奇数即可

 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "cmath"
 5 using namespace std;
 6 //const int maxn=110;
 7 int T;
 8 int n;
 9 int main()
10 {
11     cin>>T;
12     while(T--)
13     {
14         cin>>n;
15         for(int i=0;i<n;i++){
16             cout<<2*i+1<<" ";
17         }
18         cout<<endl;
19     }
20 }
View Code

Xenny and Coin Rankings

分析:水题,注意每条对角线上的rank从上到下依次增大

 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cmath"
 4 using namespace std;
 5 int T;
 6 long long u,v;
 7 int main()
 8 {
 9     cin>>T;
10     while(T--){
11         cin>>u>>v;
12         long long ans=(1+u+v)*(u+v)/2+u+1;
13         cout<<ans<<endl;
14     }
15 }
View Code

Chef and the Feast

分析:不错的一题,对于凡事正数的一定要加入集合,对于负数,我们设cnt表示解集里面的数字数量,val表示当时的和,b表示一个要判断是否要加进来的数,当(cnt+1)*(val+b)-cnt*val-b>0的时候,就可以加进来了,化简一下也就是cnt*b+val>0。对了,别忘了排序

 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "string"
 5 #include "algorithm"
 6 #include "vector"
 7 using namespace std;
 8 const int maxn=1e5+5;
 9 long long a[maxn];
10 int T,n;
11 bool cmp(long long x,long long y){
12     return x>y;
13 }
14 int main()
15 {
16     cin>>T;
17     while(T--){
18         cin>>n;
19         for(int i=0;i<n;i++)
20             cin>>a[i];
21         sort(a,a+n,cmp);
22         int cnt=0;
23         long long sum=0,val=0;
24         int flag=0;
25         for(int i=0;i<n;i++){
26             if(cnt*a[i]+val>=0&&!flag){
27                 cnt++;
28                 val+=a[i];
29                 sum=val*cnt;
30             }else{
31                 sum+=a[i];
32                 flag=1;
33             }
34         }
35         cout<<sum<<endl;
36     }
37 } 
View Code
原文地址:https://www.cnblogs.com/wolf940509/p/6963552.html