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 ...
随机推荐
- BFC的作用及其应用
简单介绍BFC BFC 就是块级格式化上下文,是页面盒模型布局中的一种 CSS 渲染模式,相当于一个独立的容器,里面的元素和外部的元素相互不影响. 创建 BFC 的方式有: 1.html的根元素 2. ...
- Appium移动端自动化测试--元素操作与触摸动作
常见自动化动作支持 click sendKeys swipe touch action 元素操作 1.click()点击操作 也可以用tab实现点击操作 driver.find_element_by_ ...
- 解决 windows oracle ORA-01113和ORA-01110错误
windows2008上的数据库版本为11.2.0.4.0,数据库打开为mount状态.报错如下: SQL> startup ORACLE instance started. Total Sys ...
- uboot中打开 debug调试信息的方法
在uboot目录下include/common.h中, 原理:只需要让 _DEBUG 的值为 1即可. 最简单的做法就是在下图第一行之前添加 #define DEBUG
- vim编辑器中的替换(转)
转1:https://www.cnblogs.com/david-wei0810/p/6385988.html 转2:https://blog.csdn.net/doubleface999/artic ...
- 0160 十分钟看懂时序数据库(I)-存储
摘要:2017年时序数据库忽然火了起来.开年2月Facebook开源了beringei时序数据库:到了4月基于PostgreSQL打造的时序数据库TimeScaleDB也开源了,而早在2016年7月, ...
- outlook 升级 及邮件同步方式设置
**office(outlook2010 32B)升级到office2016 64B时的操作 1.删除office(excel. word等) 2.选择offcie2016 安装程序安装 (outlo ...
- (五)web服务中的异常处理
一.服务端发布服务 package com.webservice; import javax.jws.WebParam; import javax.jws.WebResult; import java ...
- java调用.net的webservice接口
要调用webservice,首先得有接口,用已经写好的接口地址在myEclipse的目标project中,右键->new web service client-> 选择JAX-WS方式,点 ...
- iOS常用宏定义大全
宏定义与常量的区别 宏:只是在预处理器里进行文本替换,不做任何类型检查,宏能定义代码,const不能,多个宏编译时间相对较长,影响开发效率,调试过慢,const只会编译一次,缩短编译时间. 所以在使用 ...