codeforces-760【B二分】
来源:互联网 发布:vm文件夹 mac 编辑:程序博客网 时间:2024/04/25 06:47
题目链接:点击打开链接
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Print single integer: the number of columns the table should have.
1 7
6
1 1
5
11 6
5
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
大意:给出你一个月份和这个月的第一天是星期几;问这个日历有多少列
思路:注意一下题中给出了限制条件,给出的年份不是闰年,刚开始没注意 WA 一发
#include<iostream>#include<algorithm>#include<cstring>using namespace std;int m,d;bool judge[]={0,1,0,1,0,1,0,1,1,0,1,0,1};int main(){while(~scanf("%d%d",&m,&d)){if(m==2){if(d==1)puts("4");elseputs("5");}else if(judge[m]){if(d<=5)puts("5");elseputs("6");}else if(!judge[m]){if(d<=6)puts("5");elseputs("6");}}return 0;}
题目链接:点击打开链接
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 109, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
4 6 2
2
3 10 3
4
3 6 1
3
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
大意:有 n 张床排成一行,m 个枕头, Frodo 在第 k 个床位睡觉,问他最多能得到的枕头个数。
两个限制条件:1. 每个人至少要有一个枕头;2. 相邻两个人的枕头个数相差不能大于 1。
思路:数据这么大,二分啊。判断是否合法
#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#define LL long longusing namespace std;LL n,m,k;bool judge(LL x){LL a=min(x,k); // 等差数列长度 LL b=min(x,n-k+1); // 等差数列长度 LL sum=a*(x+x-(a-1))/2+b*(x+x-(b-1))/2-x; // 两个公差为 1 的等差数列公式 return sum<=m;}int main(){while(~scanf("%lld%lld%lld",&n,&m,&k)){m=m-n; // 保证每个人至少有一个枕头 LL mid,l=1,r=m,ans=-1;while(l<=r){mid=l+r>>1;if(judge(mid)){ans=mid;l=mid+1;}elser=mid-1;}if(ans==-1)puts("1");elseprintf("%lld\n",ans+1);}return 0;}
- codeforces-760【B二分】
- Codeforces 760B (二分)
- Codeforces 760B Frodo and pillows 【二分】
- 【Codeforces 760 B Frodo and pillows】+ 二分
- CodeForces 302B 二分
- CodeForces 600B 二分
- Codeforces 650B 二分
- Codeforces 580 B-----二分
- Codeforces 702B【二分】
- Codeforces 671B 二分
- codeforces-782【B二分】
- CodeForces 287B 二分贪心
- codeforces#321 B(排序+二分)
- codeforces#242B-Megacity-二分
- CodeForces 163B Lemmings 二分
- CodeForces 474B Worms 二分
- CodeForces 599B <二分查找-->
- Codeforces 83B Doctor(二分)
- [转载]怎么把solidworks导入到ansys中分析
- C语言实验——圆柱体计算 (sdut oj)
- JAVA之面向对象设计原则
- 链接库的时候,提示load shared libraries error,xxx file too short
- tomcat点击startup.bat后闪退
- codeforces-760【B二分】
- .Net多线程编程—使用Visual Studio 2012进行调试
- 015 - 微信小程序把玩(七)数据绑定
- 利用算法识别车厘子与樱桃
- PHPExcel基本操作
- 写给自己的笔记 ~2017~
- [Bestcoder Round#91][HDU6012] Lotus and Horticulture 排序
- bzoj 2274 [Usaco2011 Feb]Generic Cow Protests
- 线上崩溃的几个原因