A. Holidays

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

 #include<bits/stdc++.h>
using namespace std; //#define int long long signed main(){
int n;
cin>>n;
if(n%==){
int x=n/;x*=;
cout<<x<<" "<<x;
return ;
}
int ans1=;
int ans2=;
int i=;
int temp=n;
while(){
if(temp<=)
break;
if(i%)
temp-=;
else{
ans1+=min(temp,);temp-=min(temp,);
}
i++;
if(temp<=)
break;
}
i=;
temp=n;
while(){
if(temp<=)
break;
if(i%==)
temp-=;
else
ans2+=min(temp,),temp-=min(temp,);
i++;
if(temp<=)
break;
}
cout<<ans1<<" "<<ans2;
return ;
}
/*
6
1 2
7
2 2
8
2 3
9
2 4 */

B. Game of Robots

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

思路:简化M的值。

 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
#define N 1500050
int arr[N]; signed main(){
int n,m;
cin>>n>>m; for(int i=;i<=n;i++){
cin>>arr[i]; if(m<=i){
continue;
}else{
m-=i;
}
}
cout<<arr[m];
return ;
}

C. Cinema

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

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

 #include<bits/stdc++.h>

 using namespace std;
#define int long long
struct str{
int x,y,id;
}st[];
unordered_map<int,int> mp;
bool cmp(str a,str b){
if(mp[a.x]!=mp[b.x]){
return mp[a.x]>mp[b.x];
}else{
return mp[a.y]>mp[b.y];
}
}
signed main(){
int n;
cin>>n;
for(int i=;i<=n;i++){
int temp;
scanf("%lld",&temp);
mp[temp]++;
}
int m;
cin>>m;
for(int i=;i<=m;i++){
scanf("%lld",&st[i].x);
st[i].id=i;
}
for(int i=;i<=m;i++){
scanf("%lld",&st[i].y);
}
sort(st+,st++m,cmp);
cout<<st[].id;
return ;
}

D1. Magic Powder

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

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

AC代码:

 /*

 10 926
5 6 8 1 2 5 1 8 4 4
351 739 998 725 953 970 906 691 707 1000
*/
#include<bits/stdc++.h> using namespace std;
#define int long long
map<int,int> mp;
int arr[];
signed main(){
int n,m;
cin>>n>>m;
int temp;
for(int i=;i<=n;i++){
scanf("%lld",&temp);
mp[i]=temp;
}
for(int i=;i<=n;i++){
scanf("%lld",&arr[i]);
}
int ans=;
while(){
int flag=;
for(int i=;i<=n;i++){
if(arr[i]>=mp[i]){
arr[i]-=mp[i];
}else{
int x=mp[i]-arr[i];
if(x<=m){
m-=x;
arr[i]+=x;
arr[i]-=mp[i];
}else{
flag=;
break;
}
}
}
if(flag){
ans++;
}else{
break;
}
}
cout<<ans; return ;
}

D2. Magic Powder

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

 #include<bits/stdc++.h>

 using namespace std;
#define N 190000
#define int unsigned long long
int n,k;
int arr[N];
int vis[N];
signed main(){
scanf("%lld%lld",&n,&k);
for(int i=;i<=n;i++)
{
int temp;
scanf("%lld",&temp);
vis[i]=temp;
}
for(int i=;i<=n;i++)
{
scanf("%lld",&arr[i]);
}
int l=;
int r=;
while(l<=r){
int mid=(l+r)/;
int sum=;
for(int i=;i<=n;i++){
if(arr[i]<vis[i]*mid){
sum+=vis[i]*mid-arr[i];
}
if(sum>k){
break;
}
}
if(sum==k){
cout<<mid;
return ;
}else if(sum<k){
l=mid+;
}else{
r=mid-;
}
}
cout<<l-;
return ;
}

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. VS2010 安装boost库

    1.下载boost库 boost官网:www.boost.org,目前最新的版本是1.64,直接下载地址:https://dl.bintray.com/boostorg/release/1.64.0/ ...

  2. consul 初体验

    consul server: 192.168.48.134: #!/bin/bash cd /data/server/consuls nohup /data/server/consuls/consul ...

  3. css — 权重、继承性、排版、float

    目录 1. 继承性 2. css中的权重 3. 常用格式化排版 4. 浮动布局float 1. 继承性 继承性:在css有某些属性是可以继承下来,如 color,text-xxx,line-heigh ...

  4. Python习题004

    作业一:三迁举办选“帅气男孩”,评委打分可以输入打分,要求分数必须大于5,小于10: 方法一 i = 1 while i < 6: score = input("请%d评委打分:&qu ...

  5. MyBatis_02 框架

    今日内容 动态SQL语句 Xml方式 注解方式 MyBatis的缓存 MyBatis的关联查询 MyBatis逆向工程 动态SQL语句 动态SQL是什么 就是相对与固定SQL.就是通过传入的参数不一样 ...

  6. STM32之ADC实例(基于DMA方式)

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/zouleideboke/article/details/75112224 ADC简介: ADC(An ...

  7. 使用shared memory 计算矩阵乘法 (其实并没有加速多少)

    #include "cuda_runtime.h" #include "device_launch_parameters.h" #include "d ...

  8. hive 存储格式对比

    Apache Hive支持Apache Hadoop中使用的几种熟悉的文件格式,如TextFile,RCFile,SequenceFile,AVRO,ORC和Parquet格式. Cloudera I ...

  9. EF数据Linq方式查询

    using (var ctx = new NorthwindEntities()) { //单表查询SQL查询方式 //SELECT * FROM Customers AS c WHERE c.Cit ...

  10. DNSMaper 一款子域名枚举与地图标记工具

    DNSMaper DNSMaper拥有与众多子域名枚举工具相似的功能,诸如域传送漏洞检测,子域名枚举,IP地址获取 文件说明├── dnsmaper.py(核心代码)├── dnsmapper.png ...