【Codeforces Round #433 (Div. 2) B】Maxim Buys an Apartment
【链接】h在这里写链接
【题意】
【题解】
如果n%3==0,那么答案就是2*(n/3)-(k-n/3),因为多出来的被占据的位置,只能去填0了,答案就会减少(k-n/3);
如果n%3==1,也即010 010 _,这个_填0也没用,干脆用来填这个1(多余的,k--),这样就能尽量少的减少“好的位置了”
如果n%3==2,也即010 010 _ _,这里_ _中填01是最优的,则会发现和n%3==0的情况是一样的,多出来的k,每填一个0就会减少一个"好的位置",没办法减.
至于最小的答案,除非n==k,或k==0,其他都是1,否则为0
【错的次数】
【反思】
【代码】
- #include <cstdio>
- #include <iostream>
- #include <algorithm>
- #include <cstring>
- #include <vector>
- #include <map>
- #include <queue>
- #include <iomanip>
- #include <set>
- #include <cstdlib>
- #include <cmath>
- #include <bitset>
- using namespace std;
- #define lson l,m,rt<<1
- #define rson m+1,r,rt<<1|1
- #define LL long long
- #define rep1(i,a,b) for (int i = a;i <= b;i++)
- #define rep2(i,a,b) for (int i = a;i >= b;i--)
- #define mp make_pair
- #define pb emplace_back
- #define fi first
- #define se second
- #define ld long double
- #define ms(x,y) memset(x,y,sizeof x)
- #define ri(x) scanf("%d",&x)
- #define rl(x) scanf("%lld",&x)
- #define rs(x) scanf("%s",x)
- #define rf(x) scnaf("%lf",&x)
- #define oi(x) printf("%d",x)
- #define ol(x) printf("%lld",x)
- #define oc putchar(' ')
- #define os(x) printf(x)
- #define all(x) x.begin(),x.end()
- #define Open() freopen("F:\\rush.txt","r",stdin)
- #define Close() ios::sync_with_stdio(0)
- #define sz(x) ((int) x.size())
- #define ld long double
- typedef pair<int,int> pii;
- typedef pair<LL,LL> pll;
- //mt19937 myrand(time(0));
- //int get_rand(int n){return myrand()%n + 1;}
- const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
- const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
- const double pi = acos(-1.0);
- const int N = 110;
- int n,k;
- int main(){
- //Open();
- //Close();
- ri(n),ri(k);
- int mi;
- if (n > k && k >0)
- mi = 1;
- else
- mi = 0;
- if (n==1){
- puts("0 0");
- return 0;
- }
- int temp = n/3;
- int ju = n%3;
- int ma = temp*2;
- if (k <= temp){
- ma-= (temp-k)*2;
- }else{
- // k > temp
- if (ju==1){
- k--;
- }
- if (ju==2){
- k--;
- ma++;
- }
- ma -= (k-temp);
- }
- oi(mi),oc,oi(ma),puts("");
- return 0;
- }
【Codeforces Round #433 (Div. 2) B】Maxim Buys an Apartment的更多相关文章
- 【Codeforces Round #433 (Div. 1) B】Jury Meeting
[链接]h在这里写链接 [题意] 有n个人,它们都要在某一时刻开始,全都到达0位置,然后维持最少k个时间单位,然后再全都回到原来的位置; 第i个人初始的位置是i. 且一共有m班航班. 每一班航班,要么 ...
- 【Codeforces Round #433 (Div. 2) C】Planning
[链接]h在这里写链接 [题意] 让你确定ti,使得∑(ti-i)*gi最小,其中ti∈[k+1..k+n],且每个ti都不能一样. 且ti>=i必须成立. [题解] 分解一下成为∑ti*gi ...
- 【Codeforces Round #433 (Div. 2) A】Fraction
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 枚举分子从高到低就好. 这样得到的一定是最大的. (可以约分没错,但是约分过后和就不是n了,所以不会有错的) [错的次数] 0 [反思] 在这 ...
- 【Codeforces Round #433 (Div. 1) C】Boredom(二维线段树)
[链接]我是链接 [题意] 接上一篇文章 [题解] 接(点我进入)上一篇文章. 这里讲一种用类似二维线段树的方法求矩形区域内点的个数的方法. 我们可以把n个正方形用n棵线段树来维护. 第i棵线段树维护 ...
- 【Codeforces Round #433 (Div. 1) C】Boredom(树状数组)
[链接]h在这里写链接 [题意] 给你一个n*n的矩阵. 其中每一列都有一个点. 任意两个点构成了矩形的两个对角点 ->即任意两个点确定了一个矩形. ->总共能确定n*(n-1)/2个矩形 ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
随机推荐
- 构建基于Javascript的移动CMS——加入滑动
在和几个有兴趣做移动CMS的小伙伴讨论了一番之后,我们认为当前比較重要的便是统一一下RESTful API.然而近期持续断网中,又遭遇了一次停电,暂停了对API的思考.在周末无聊的时光了看了<人 ...
- 论Nim中的 proc 和 method
在Nim中.proc 是定义过程的keyword.method 是定义方法的keyword.它们之间根本的差别是proc定义的过程是静态绑定.method定义的方法是动态绑定.谈到静态绑定.动态绑定又 ...
- Java源代码之集合框架(图)
百度"java 集合"图时.搜出来一张图.图蛮不错的.跟大家分享下.
- PopupMenu-使用实例跟监听事件
今天需要给一个控件添加弹出菜单功能.就顺便学习了下popupMenu的使用,记录下来. 它的使用其实也非常的简单,看如下代码 popupMenu = new PopupMenu(MainActivit ...
- 8.AXIS1基础
转自:https://blog.csdn.net/chjttony/article/details/6209998 1.AXIS简介: Axis是Apache组织推出的SOAP引擎,Axis项目是Ap ...
- 分享一下10个常用jquery片段
1. 图片预加载 (function($) { var cache = []; // Arguments are image paths relative to the current page. ...
- HTML 页面内容禁止选中
写一个小笔记,怎么禁止HTML页面不被选中,复制. CSS: *{ moz-user-select: -moz-none; -moz-user-select: none; -o-user-select ...
- exit---退出目前的shell
exit命令 exit命令同于退出shell,并返回给定值.在shell脚本中可以终止当前脚本执行.执行exit可使shell以指定的状态值退出.若不设置状态值参数,则shell以预设值退出.状态 ...
- 微信小程序从零开始开发步骤(一)搭建开发环境
从零到有写一个小程序系列专题,很早以前就想写来分享,但由于项目一直在进展,没有过多的时间研究技术,现在可以继续分享了. 1:注册 用没有注册过微信公众平台的邮箱注册一个微信公众号, 申请帐号 ,网址: ...
- hdu2768Cat vs. Dog (反建法,最大独立集)
Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...