A. Holidays

题意:一个星球 五天工作,两天休息。给你一个1e6的数字n,问你最少和最多休息几天。
思路:我居然写成模拟题QAQ。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. //#define int long long
  5.  
  6. signed main(){
  7. int n;
  8. cin>>n;
  9. if(n%==){
  10. int x=n/;x*=;
  11. cout<<x<<" "<<x;
  12. return ;
  13. }
  14. int ans1=;
  15. int ans2=;
  16. int i=;
  17. int temp=n;
  18. while(){
  19. if(temp<=)
  20. break;
  21. if(i%)
  22. temp-=;
  23. else{
  24. ans1+=min(temp,);temp-=min(temp,);
  25. }
  26. i++;
  27. if(temp<=)
  28. break;
  29. }
  30. i=;
  31. temp=n;
  32. while(){
  33. if(temp<=)
  34. break;
  35. if(i%==)
  36. temp-=;
  37. else
  38. ans2+=min(temp,),temp-=min(temp,);
  39. i++;
  40. if(temp<=)
  41. break;
  42. }
  43. cout<<ans1<<" "<<ans2;
  44. return ;
  45. }
  46. /*
  47. 6
  48. 1 2
  49. 7
  50. 2 2
  51. 8
  52. 2 3
  53. 9
  54. 2 4
  55.  
  56. */

B. Game of Robots

题意:第一个机器人报自己的编号;第二个报前一个机器人和自己的编号;第三个机器人报前两个机器人和自己的编号。以此类推。
每个机器人一个编号。问k个报什么。

思路:简化M的值。

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define int unsigned long long
  7. #define N 1500050
  8. int arr[N];
  9.  
  10. signed main(){
  11. int n,m;
  12. cin>>n>>m;
  13.  
  14. for(int i=;i<=n;i++){
  15. cin>>arr[i];
  16.  
  17. if(m<=i){
  18. continue;
  19. }else{
  20. m-=i;
  21. }
  22. }
  23. cout<<arr[m];
  24. return ;
  25. }

C. Cinema

题意:有n个人,每个人只会一种语言(不同编号表不同语言)。
现在有m部电影,每部电影的声音是a[i],字幕是b[i]。(a[i]输入完输入b[i])
如果听得懂声音,他会非常满意,如果字幕他能看懂的话他会比较满意,否则它很不满意。
现在问看哪部电影会使得n个人满意最高(如果两部电影使n个人非常满意的人数相同时,选比较满意的最多的)。

思路:看了一些大佬的博客,都是用离散化。可是菜菜的我不会离散化QAQ。结果用个哈希MAP。居然水过。unordered_map<int,int> mp是个好东西。。。。。。。。。。。

  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define int long long
  5. struct str{
  6. int x,y,id;
  7. }st[];
  8. unordered_map<int,int> mp;
  9. bool cmp(str a,str b){
  10. if(mp[a.x]!=mp[b.x]){
  11. return mp[a.x]>mp[b.x];
  12. }else{
  13. return mp[a.y]>mp[b.y];
  14. }
  15. }
  16. signed main(){
  17. int n;
  18. cin>>n;
  19. for(int i=;i<=n;i++){
  20. int temp;
  21. scanf("%lld",&temp);
  22. mp[temp]++;
  23. }
  24. int m;
  25. cin>>m;
  26. for(int i=;i<=m;i++){
  27. scanf("%lld",&st[i].x);
  28. st[i].id=i;
  29. }
  30. for(int i=;i<=m;i++){
  31. scanf("%lld",&st[i].y);
  32. }
  33. sort(st+,st++m,cmp);
  34. cout<<st[].id;
  35. return ;
  36. }

D1. Magic Powder

题意:做一个蛋糕需要n个原材料,现有k个魔法材料,魔法材料可以替代成任何材料,现在告诉你蛋糕每个材料需要多少,以及你现在有多少个,问你最多能够做出多少个蛋糕来。

思路:看了一下数据范围,然后开始暴力。

AC代码:

  1. /*
  2.  
  3. 10 926
  4. 5 6 8 1 2 5 1 8 4 4
  5. 351 739 998 725 953 970 906 691 707 1000
  6. */
  7. #include<bits/stdc++.h>
  8.  
  9. using namespace std;
  10. #define int long long
  11. map<int,int> mp;
  12. int arr[];
  13. signed main(){
  14. int n,m;
  15. cin>>n>>m;
  16. int temp;
  17. for(int i=;i<=n;i++){
  18. scanf("%lld",&temp);
  19. mp[i]=temp;
  20. }
  21. for(int i=;i<=n;i++){
  22. scanf("%lld",&arr[i]);
  23. }
  24. int ans=;
  25. while(){
  26. int flag=;
  27. for(int i=;i<=n;i++){
  28. if(arr[i]>=mp[i]){
  29. arr[i]-=mp[i];
  30. }else{
  31. int x=mp[i]-arr[i];
  32. if(x<=m){
  33. m-=x;
  34. arr[i]+=x;
  35. arr[i]-=mp[i];
  36. }else{
  37. flag=;
  38. break;
  39. }
  40. }
  41. }
  42. if(flag){
  43. ans++;
  44. }else{
  45. break;
  46. }
  47. }
  48. cout<<ans;
  49.  
  50. return ;
  51. }

D2. Magic Powder

二分做法。感觉以前做过类似的题目。

  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define N 190000
  5. #define int unsigned long long
  6. int n,k;
  7. int arr[N];
  8. int vis[N];
  9. signed main(){
  10. scanf("%lld%lld",&n,&k);
  11. for(int i=;i<=n;i++)
  12. {
  13. int temp;
  14. scanf("%lld",&temp);
  15. vis[i]=temp;
  16. }
  17. for(int i=;i<=n;i++)
  18. {
  19. scanf("%lld",&arr[i]);
  20. }
  21. int l=;
  22. int r=;
  23. while(l<=r){
  24. int mid=(l+r)/;
  25. int sum=;
  26. for(int i=;i<=n;i++){
  27. if(arr[i]<vis[i]*mid){
  28. sum+=vis[i]*mid-arr[i];
  29. }
  30. if(sum>k){
  31. break;
  32. }
  33. }
  34. if(sum==k){
  35. cout<<mid;
  36. return ;
  37. }else if(sum<k){
  38. l=mid+;
  39. }else{
  40. r=mid-;
  41. }
  42. }
  43. cout<<l-;
  44. return ;
  45. }

Codeforces Round #350 (Div. 2) A B C D1 D2 水题【D2 【二分+枚举】好题】的更多相关文章

  1. Codeforces Round #350 (Div. 2)A,B,C,D1

    A. Holidays time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  2. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

  3. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟

    题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...

  4. Codeforces Round #350 (Div. 2) D2. Magic Powder - 2

    题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...

  5. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)

    题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...

  6. Codeforces Round #350 (Div. 2)解题报告

    codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...

  7. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表

    E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description ...

  8. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

  9. Codeforces Round #350 (Div. 2) C. Cinema 水题

    C. Cinema 题目连接: http://www.codeforces.com/contest/670/problem/C Description Moscow is hosting a majo ...

随机推荐

  1. BFC的作用及其应用

    简单介绍BFC BFC 就是块级格式化上下文,是页面盒模型布局中的一种 CSS 渲染模式,相当于一个独立的容器,里面的元素和外部的元素相互不影响. 创建 BFC 的方式有: 1.html的根元素 2. ...

  2. Appium移动端自动化测试--元素操作与触摸动作

    常见自动化动作支持 click sendKeys swipe touch action 元素操作 1.click()点击操作 也可以用tab实现点击操作 driver.find_element_by_ ...

  3. 解决 windows oracle ORA-01113和ORA-01110错误

    windows2008上的数据库版本为11.2.0.4.0,数据库打开为mount状态.报错如下: SQL> startup ORACLE instance started. Total Sys ...

  4. uboot中打开 debug调试信息的方法

    在uboot目录下include/common.h中, 原理:只需要让 _DEBUG 的值为 1即可. 最简单的做法就是在下图第一行之前添加 #define DEBUG

  5. vim编辑器中的替换(转)

    转1:https://www.cnblogs.com/david-wei0810/p/6385988.html 转2:https://blog.csdn.net/doubleface999/artic ...

  6. 0160 十分钟看懂时序数据库(I)-存储

    摘要:2017年时序数据库忽然火了起来.开年2月Facebook开源了beringei时序数据库:到了4月基于PostgreSQL打造的时序数据库TimeScaleDB也开源了,而早在2016年7月, ...

  7. outlook 升级 及邮件同步方式设置

    **office(outlook2010 32B)升级到office2016 64B时的操作 1.删除office(excel. word等) 2.选择offcie2016 安装程序安装 (outlo ...

  8. (五)web服务中的异常处理

    一.服务端发布服务 package com.webservice; import javax.jws.WebParam; import javax.jws.WebResult; import java ...

  9. java调用.net的webservice接口

    要调用webservice,首先得有接口,用已经写好的接口地址在myEclipse的目标project中,右键->new web service client-> 选择JAX-WS方式,点 ...

  10. iOS常用宏定义大全

    宏定义与常量的区别 宏:只是在预处理器里进行文本替换,不做任何类型检查,宏能定义代码,const不能,多个宏编译时间相对较长,影响开发效率,调试过慢,const只会编译一次,缩短编译时间. 所以在使用 ...