【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 ...
随机推荐
- tomcat 分别在window 和 Linux上配置SSL-安全问题
公司项目收尾后.通过压力測试后的安全測试.安全測试后中,对于网络传输中数据加密问题存在安全隐患. 须要配置SSL. 简介下SSL协议:SSL或者Secure Socket Layer,是一种同意web ...
- 使用QML自绘页面导航条
使用QML自绘页面导航条 近期使用QML制作项目,依照要求.须要制作成分页的插件.遗憾的是,QML的控件库Qt Quick都没有现成的控件,于是我尝试着自己实现自绘页面导航条. 原创文章,反对未声明的 ...
- es67
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Springboot优化
https://www.cnblogs.com/chen110xi/p/6198481.html
- 37.cgi网页交互
1.Apache的安装 地址:链接:https://pan.baidu.com/s/1kWdSWwZ 密码:nuqo 2.在相应路径下写html如图所示 new.html代码: <html> ...
- java使double保留两位小数的多方法
java使double保留两位小数的多方法 java保留两位小数 mport java.text.DecimalFormat; DecimalFormat df = new DecimalFormat ...
- 体验域名注册解析与SSL证书
- js对象拷贝的方法
对象拷贝的方法是一个难点,尤其是深拷贝.建议把代码都运行下,帮助理解拷贝. 一. json方法 1. 适合情况: JSON对象的深度克隆.方法是先JSON.stringify() 转为json字符 ...
- chkconfig---检查设置系统服务
chkconfig命令 chkconfig命令检查.设置系统的各种服务.这是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务 ...
- 微信小程序从零开始开发步骤(二)创建小程序页面
上一章注册完小程序,添加新建的项目,大致的准备开发已经完成,本章要分享的是 要创建一个简单的页面了,创建小程序页面的具体几个步骤: 1. 在pages 中添加一个目录 选中page,右击鼠标,从硬盘打 ...