Educational Codeforces Round 85 (Rated for Div. 2)

题目链接:http://codeforces.com/contest/1334/

A

思路:按照题意模拟下就行了,注意情况不要漏考虑,差值的比较

 1 //-------------------------------------------------
 2 //Created by HanJinyu
 3 //Created Time :二  4/21 21:10:17 2020
 4 //File Name :85A.cpp
 5 //-------------------------------------------------
 6 
 7 #include <stdio.h>
 8 #include <string.h>
 9 #include <iostream>
10 #include <algorithm>
11 #include <vector>
12 #include <queue>
13 #include <set>
14 #include <map>
15 #include <list>
16 #include <map>
17 #include <string>
18 #include <math.h>
19 #include <stdlib.h>
20 #include <time.h>
21 using namespace std;
22 typedef double db;
23 typedef long long ll;
24 const int maxn = 200005;
25 
26 int main()
27 {
28     //freopen("in.txt","r",stdin);
29     //freopen("out.txt","w",stdout);
30     int t;
31     scanf("%d",&t);
32     while(t--)
33     {
34         int n;
35         scanf("%d",&n);
36         int a[maxn],b[maxn];
37         bool flag=false;
38         for(int i=0;i<n;i++){
39             scanf("%d%d",&a[i],&b[i]);
40             if(b[i]>a[i])
41                 flag=true;
42             if(i!=0&&b[i]<b[i-1])
43                 flag=true;
44             if(i!=0&&a[i]<a[i-1])
45                 flag=true;
46             if(i!=0&&a[i]>a[i-1]&&b[i]<b[i-1])
47                 flag=true;
48             if(i!=0&&b[i]>b[i-1]&&a[i]<=a[i-1])
49                 flag=true;
50             if(i!=0&&((b[i]-b[i-1])>(a[i]-a[i-1])))
51                 flag=true;
52         }
53         if(flag)
54             printf("NO
");
55         else
56             printf("YES
");
57     }
58  
59      return 0;
60 }
View Code

B

思路:求和除以n看结果是不是大于等于x,如果是,那么直接输出n,其次,将数组降序排序,一位一位考虑,用和累加之前的值,当和除以当前值得位置+1即个数的时候,看这些个数的平均值是否大于等于x,如果小于x直接退出,当前位置+1即是所求个数了

 1 //-------------------------------------------------
 2 //Created by HanJinyu
 3 //Created Time :二  4/21 22:00:15 2020
 4 //File Name :85B.cpp
 5 //-------------------------------------------------
 6 
 7 #include <stdio.h>
 8 #include <string.h>
 9 #include <iostream>
10 #include <algorithm>
11 #include <vector>
12 #include <queue>
13 #include <set>
14 #include <map>
15 #include <list>
16 #include <map>
17 #include <string>
18 #include <math.h>
19 #include <stdlib.h>
20 #include <time.h>
21 using namespace std;
22 typedef double db;
23 typedef long long ll;
24 const int maxn = 200005;
25 
26 int main()
27 {
28     //freopen("in.txt","r",stdin);
29     //freopen("out.txt","w",stdout);
30     int t;
31     scanf("%d",&t);
32     while(t--){
33         ll sum=0;
34         ll y[maxn];
35         ll n,x;
36         scanf("%lld %lld",&n,&x);
37         for(int i=0;i<n;i++)
38         {
39             scanf("%lld",&y[i]);
40             sum+=y[i];
41         }
42         if(sum/n>=x)
43             printf("%lld
",n);
44         else{
45             sort(y,y+n,greater<ll>());
46             if(y[0]<x)
47             {
48 
49                 printf("0
");
50                 continue;
51             }
52             ll ss=0;
53             ll r=0;
54             for(int i=0;i<n;i++)
55             {
56                 ss+=y[i];
57                 if(ss/(i+1)>=x)
58                    r=(i+1);
59                 else
60                     break;
61             }
62             printf("%lld
",r);
63         }
64     }
65  
66      return 0;
67 }
View Code

 C

思路:脑子转不过来,用了一个比较好理解的方法,他是按照顺序来杀怪物的,那么用一个res数组来记录a[i]-b[i-1],当res[i]大于0的时候,将其累加起来,这个和算的是如果不杀作为第一个数所用子弹数的总和,然后枚举每种情况,杀a[i]时所要花费的子弹数,这时候就要减去自身的res[i]的值,因为跟上一个怪物的爆炸值没有关系,因此这个sum和里包含的res[i]值要减去,这时候是除了自身其他杀死怪物所要的子弹数,当然还要加上自身的a[i]值,这才是杀死当前怪物所用的所有子弹数,注意当res[i]<0的时候就是这个怪物可以完全被爆炸掉,减去res[i]的时候判断是否大于0就行,因为负的不在sum和之中,因此不用减去,最后所有情况求最小值即可。

//-------------------------------------------------
//Created by HanJinyu
//Created Time :四  4/30 12:48:30 2020
//File Name :85C.cpp
//-------------------------------------------------

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef double db;
typedef long long ll;
const int maxn = 200005;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int t,n;
    scanf("%d",&t);
    while(t--)
    {

        scanf("%d",&n);
        ll a[n],b[n];
        for(int i=0;i<n;i++)
            scanf("%lld%lld",a+i,b+i);
        ll res[n],sum=0;
        for(int i=0;i<n;i++)
        {
            if(i==0)
                res[i]=a[i]-b[n-1];
            else
                res[i]=a[i]-b[i-1];
            if(res[i]>0)
                sum+=res[i];
        }
        ll he=1e18;
        for(int i=0;i<n;i++)
        {
            he=min(he,sum+a[i]-max(0ll,res[i]));
        }
        printf("%lld
",he);
    }
 
     return 0;
}
View Code
原文地址:https://www.cnblogs.com/Vampire6/p/12749208.html