A. Heating (水题)

题目链接

大致思路:

因为是代价是平方,所以让每一个房间的大小平均即可,即最大和最小相差不超过一。

代码:

  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. ll n;
  5. int main()
  6. {
  7. //freopen("H:\\c++1\\in.txt","r",stdin);
  8. //freopen("H:\\c++1\\out.txt","w",stdout);
  9. ll c,sum;
  10. scanf("%lld",&n);
  11. while(n--){
  12. scanf("%lld%lld",&c,&sum);
  13. ll s=sum/c,yu=sum%c,ans=0;
  14. //cout<<s<<" "<<yu<<endl;
  15. for(int i=1;i<=min(c,sum);i++){
  16. if(yu){
  17. ans+=(s+1)*(s+1);yu--;
  18. }else{
  19. ans+=(s)*(s);
  20. }
  21. }
  22. printf("%lld\n",ans);
  23. }
  24. return 0;
  25. }

B. Obtain Two Zeroes (找结论)

题目链接

大致思路:

首先观察到 \((0,0)\) 态是可行的,那么其可以转移到的状态也是可行的,由于是加上 \(,x,2x\) ,那么 \((a,b)\) 的 \(a+b\) 必然是 \(3\) 的倍数,而且可以知道较大数不能大于较小的数两倍,虽然这只是必要条件,还是不够严谨,但是能过。

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. //freopen("H:\\c++1\\in.txt","r",stdin);
  6. //freopen("H:\\c++1\\out.txt","w",stdout);
  7. int n,a,b;
  8. scanf("%d",&n);
  9. while(n--){
  10. scanf("%d%d",&a,&b);
  11. if((a+b)%3==0&&max(a,b)<=2*min(a,b)){
  12. puts("YES");
  13. }
  14. else puts("NO");
  15. }
  16. return 0;
  17. }

C. Infinite Fence (数学)

题目链接

大致思路:

假设 \(r>b\) ,主要是判断在 \((m1*r,(m1+1)*r)\) 之中b的倍数最多出现多次。所以要找到一个 \(m*b\%r\) 的最小值,可以知道这个值就是 \(gcd(b,r)\) ,那么我们其实就是判断 \(gcd(b,r)+(k-1)*b\) 和 \(r\) 的关系就行了。

代码:

  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. ll gcd(ll a,ll b){
  5. return b==0?a:gcd(b,a%b);
  6. }
  7. ll T,r,b,k;
  8. int main()
  9. {
  10. //freopen("H:\\c++1\\in.txt","r",stdin);
  11. //freopen("H:\\c++1\\out.txt","w",stdout);
  12. scanf("%lld",&T);
  13. while(T--){
  14. scanf("%lld%lld%lld",&r,&b,&k);
  15. if(r==b){ // 特判一个相等的情况,不够其实不用好像
  16. puts("OBEY");continue;
  17. }
  18. if(r<b)swap(r,b);
  19. if(r%b==0){
  20. if(k*b<r){
  21. puts("REBEL");
  22. }else puts("OBEY");
  23. continue;
  24. }
  25. ll g=gcd(r,b);
  26. if(g+(k-1)*b<r){
  27. puts("REBEL");
  28. }else puts("OBEY");
  29. }
  30. return 0;
  31. }

D. A Game with Traps (二分+贪心)

题目链接

大致思路:

首先最容易想的二分带的人数,然后进行判断,重点是怎么判断。发现无论如何部队必然要走 \(n+1\)步,那么我们可以不用去管,那么对于两个雷 \((l_1,r_1),(l_2,r_2)\), 如果 \(l_2<=r_1\) ,那么最优的方法就是一次性走到 \(r_2\) 再回来带人,否则就正常模拟。

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int N=2e5+10;
  4. int a[N];
  5. int n,m,k,t;
  6. struct node{
  7. int l,r,d;
  8. node(int a=0,int b=0,int c=0){l=a,r=b,d=c;}
  9. }lei[N];
  10. vector<node>tt;
  11. bool cmp(node a,node b){
  12. return a.l<b.l;
  13. }
  14. bool check(int x){
  15. tt.clear();
  16. int nl=a[x];
  17. for(int i=1;i<=k;i++)if(lei[i].d>nl)tt.push_back(lei[i]);//有危险的雷
  18. if(tt.size()==0)return 1;
  19. int ans=n+1,mx=0,now=tt[0].l-1;//部队行动距离必然要为n+1
  20. for(int i=0;i<int(tt.size());i++){
  21. mx=tt[i].r;
  22. int j=i+1;
  23. while(j<int(tt.size())&&tt[j].l<=mx)mx=max(mx,tt[j].r),j++;//有交集
  24. ans+=(mx-now)*2;
  25. now=tt[j].l-1;//更新
  26. i=j-1;
  27. }
  28. //cout<<x<<" "<<ans<<endl;
  29. if(ans<=t)return 1;//比较
  30. else return 0;
  31. }
  32. int main()
  33. {
  34. //freopen("H:\\c++1\\in.txt","r",stdin);
  35. //freopen("H:\\c++1\\out.txt","w",stdout);
  36. scanf("%d%d%d%d",&m,&n,&k,&t);
  37. for(int i=1;i<=m;i++)scanf("%d",&a[i]);
  38. sort(a+1,a+1+m);//按能力排序
  39. reverse(a+1,a+1+m);//降序
  40. for(int i=1;i<=k;i++){
  41. scanf("%d%d%d",&lei[i].l,&lei[i].r,&lei[i].d);
  42. }
  43. sort(lei+1,lei+1+k,cmp);//按l排序
  44. int ans=0,l=1,r=m;
  45. while(l<=r){//二分
  46. int mid=(l+r)/2;
  47. if(check(mid)){
  48. ans=mid;l=mid+1;
  49. }else r=mid-1;
  50. }
  51. printf("%d\n",ans);
  52. return 0;
  53. }

E. Tournament (贪心)

题目链接

大致思路:

我们发现每一轮都会淘汰一些人,我们的贪心策略就是让力量大的人尽量淘汰更多的人,那么我们就可以减少花费,而且在 \(k\) 轮,对于前 \(2^k-1\) 个人我们就不能选择,因为他们必定淘汰,所以我们从后面开始,每次选择我们可以选择的人花费最小的就行。

代码:

  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. const int N=(1<<20);
  5. int n;
  6. int a[N];
  7. int vis[N];
  8. multiset<int>s;
  9. int main()
  10. {
  11. /* freopen("H:\\c++1\\in.txt","r",stdin);
  12. freopen("H:\\c++1\\out.txt","w",stdout);
  13. */ scanf("%d",&n);
  14. for(int i=1;i<=n;i++)scanf("%d",&a[i]);
  15. for(int i=0;(1<<i)<=n;i++)vis[(1<<i)]=1;
  16. ll ans=0;
  17. for(int i=n;i>=1;i--){
  18. if(a[i]==-1)break;
  19. s.insert(a[i]);
  20. if(vis[i]){//选择可以选的代价最小的人
  21. ans+=*(s.begin());
  22. s.erase(s.begin());
  23. }
  24. }
  25. printf("%lld\n",ans);
  26. return 0;
  27. }

CF-Educational Codeforces Round 77 (Rated for Div. 2)(A-E题解)的更多相关文章

  1. 【cf比赛记录】Educational Codeforces Round 77 (Rated for Div. 2)

    比赛传送门 这场题目前三题看得挺舒服的,没有臃肿的题目,对于我这种英语渣渣就非常友好,但因为太急了,wa了两发A后才意识到用模拟(可以删了,博主真的是个菜鸟),结果导致心态大崩 ---- 而且也跟最近 ...

  2. Educational Codeforces Round 77 (Rated for Div. 2) D A game with traps

    题意:x正轴上有着一个陷阱的位置,开关和灵敏度,如果一个士兵灵敏度输给陷阱,他是过不去这个陷阱的幸运的是,你可以先过去把开关给关了,没错你是不怕陷阱的接下来呢你有操作,你移动一个,耗费一秒而你的团队需 ...

  3. Educational Codeforces Round 77 (Rated for Div. 2)

    A: 尽可能平均然后剩下的平摊 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int ...

  4. Codeforce |Educational Codeforces Round 77 (Rated for Div. 2) B. Obtain Two Zeroes

    B. Obtain Two Zeroes time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Educational Codeforces Round 77 (Rated for Div. 2)D(二分+贪心)

    这题二分下界是0,所以二分写法和以往略有不同,注意考虑所有区间,并且不要死循环... #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> ...

  6. Educational Codeforces Round 77 (Rated for Div. 2) - D. A Game with Traps(二分)

    题意:$m$个士兵,每个士兵都有一个灵敏度$a[i]$,起点为$0$,终点为$n + 1$,在路上有$k$个陷阱,每个陷阱有三个属性$l[i],r[i],d[i]$,$l[i]$表示陷阱的位置,如果你 ...

  7. Educational Codeforces Round 77 (Rated for Div. 2) C. Infinite Fence

    C. Infinite Fence 题目大意:给板子涂色,首先板子是顺序的,然后可以涂两种颜色,如果是r的倍数涂成红色,是b的倍数涂成蓝色, 连续的k个相同的颜色则不能完成任务,能完成任务则输出OBE ...

  8. Educational Codeforces Round 61 (Rated for Div. 2) D,F题解

    D. Stressful Training 题目链接:https://codeforces.com/contest/1132/problem/D 题意: 有n台电脑,每台电脑都有初始电量ai,也有一个 ...

  9. Educational Codeforces Round 81 (Rated for Div. 2) A-E简要题解

    链接:https://codeforces.com/contest/1295 A. Display The Number 贪心思路,尽可能放置更多位,如果n为奇数,消耗3去放置一个7,剩下的放1 AC ...

  10. Educational Codeforces Round 65 (Rated for Div. 2)题解

    Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...

随机推荐

  1. Hibernate学习:Exception in thread "main" java.lang.NullPointerException

    1.在学习Hibernate多对多关系的时候遇到了一下异常: 主函数出现了空指针异常: public static void testadd() { Session session = Hiberna ...

  2. cpu的发现

    system.cpu.discovery 检测到的CPU/CPU内核列表.用于低级发现 返回的cpu从0开始编号,其他关于cpu的监控项就可以使用cpu的id进行单个cpu的资源监控

  3. [RN] React Native 实现 类似京东 的 沉浸式状态栏和搜索栏

    React Native 实现 类似京东 的 沉浸式状态栏和搜索栏 其原理其实就是在要 隐藏 部分的那个View 前面加入 StatusBar 代码! 代码如下: <StatusBar anim ...

  4. <转>python列表、元组、集合、字典、json相互转换以及其他基础入门

    列表元组转其他 # 列表转集合(去重) list1 = [6, 7, 7, 8, 8, 9] set(list1) # {6, 7, 8, 9} #两个列表转字典 list1 = ['key1','k ...

  5. JMeter的基本使用

    什么是Jmeter JMeter是Apache基于Java开发的压力测试工具,通俗的说,你想知道你的接口有多猛,你的服务器是否耐揍,这个家伙可以用数据告诉你.原来学过JMeter的基本使用,发现想不起 ...

  6. SQL Mode

    SQL Mode简介 在MySQL中,SQL Mode常常用来解决以下问题: 1.通过设置SQL Mode,可以完成不同严格程度的数据校验,有效保证数据准确性. 2.通过设置SQL Mode为ANSI ...

  7. limma 包

    limma:Linear Models for Microarray and RNA-Seq Data http://www.bioconductor.org/packages/release/bio ...

  8. mariadb新安装解决远程访问以及root登录

    mariadb新安装解决远程访问以及root登录一.修改/etc/mysql/my.conf找到bind-address = 127.0.0.1这一行直接#掉或者改为bind-address = 0. ...

  9. 运行虚拟机报错:CPU acceleration status: HAXM is not installed on this machine

    运行虚拟机报错:CPU acceleration status: HAXM is not installed on this machine. 这是因为SDKmanage没有安装HAXM ,于是打开S ...

  10. 11 JavaScript Utility Libraries you Should Know in 2019

    11 Useful Javascript utility libraries to speed your development.