Codeforces Round #350 (Div. 2) A B C D1 D2 水题【D2 【二分+枚举】好题】
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 【二分+枚举】好题】的更多相关文章
- 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 ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟
题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2
题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)
题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...
- Codeforces Round #350 (Div. 2)解题报告
codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表
E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description ...
- Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...
- Codeforces Round #350 (Div. 2) C. Cinema 水题
C. Cinema 题目连接: http://www.codeforces.com/contest/670/problem/C Description Moscow is hosting a majo ...
随机推荐
- JAVA支持字符编码读取文件
文件操作,在java中很常用,对于存在特定编码的文件,则需要根据字符编码进行读取,要不容易出现乱码 /** * 读取文件 * @param filePath 文件路径 */ public static ...
- GBK字符集
GBK字库 编辑 同义词 GBK一般指GBK字库 GBK全称<汉字内码扩展规范>(GBK即“国标”.“扩展”汉语拼音的第一个字母,英文名称:Chinese Internal Code Sp ...
- matplotlib笔记1
散点图-scatter 散点图显示两组数据的值,每个点的坐标位置由变量的值决定由一组不连接的点完成,用于观察两种变量的相关 import numpy as np import matplotlib.p ...
- Scratch运动模块——有趣的弹球游戏(一)
大家好!我是蓝老师,有了前几期Scratch的基础,相信大家早已摩拳擦掌,跃跃欲试了,甚至还有些小伙伴已经编写了非常不错的程序. 学习编程就是这样不断探索.主动思考.解决问题的过程. 本期内容: 课程 ...
- css 背景 background
前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! background我们一般用到的的属性有: background-attachment:背景(图片)是否 ...
- 微软发布云端基因服务:推动AI驱动的精准医疗
微软发布云端基因服务:推动AI驱动的精准医疗 2018年03月07日 00:00:00 微软研究院AI头条 阅读数:117 版权声明:本文为博主原创文章,未经博主允许不得转载. https:// ...
- 修改ubuntu设备名
修改ubuntu设备名 执行如下命令: sudo sed -i 's/当前设备名/新设备名/' /etc/hostname sudo sed -i 's/当前设备名/新设备名/' /etc/h ...
- Django2.0 开始一个项目
python项目运行环境: 安装虚拟环境工具 pip install virtualenv 使用虚拟环境: 创建虚拟环境: virtualenv <虚拟环境名称> 进去虚拟环境: S ...
- Linux 命令实战
命令登录 ssh UserName@RemoteIP ssh seemmo@192.168.0.1 统计文件.目录的数量 统计当前目录下文件数量:ls -l | grep "^- ...
- RE:ゼロから始める AFO 生活
新建这篇博客的时候发现自己在NOI之后只发过两三篇博客,而且都基本上没什么实质性内容. 果然是巨大混混人啊. 本文承接上篇(不过好像烂尾了),旨在记录一些有趣(?)的内容. 12.23 北大集训过去好 ...