码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #393 (Div. 2)

时间:2017-01-24 21:49:01      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:water   ros   pillow   int   ide   ted   max   ret   src   

A - Petr and a calendar (water)

题意:在2017年,m是月份,d是这个月第一个是星期几。问这个月的日历需要多少行。
技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int INF = 0x3f3f3f3f;
 4 const int maxn = 100 + 5;
 5 typedef long long LL;
 6 typedef pair<int, int>pii;
 7 
 8 int main()
 9 {
10     int n, m;
11     cin >> n >> m;
12     int d;
13     if(n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10 || n == 12)
14     {
15         //31
16         d = 31 - (7 - m + 1);
17     }
18     else if(n == 2)
19     {
20         //28
21         d = 28 - (7 - m + 1);
22     }
23     else
24     {
25         d = 30 - (7 - m + 1);
26     }
27     cout << (d + 6) / 7 + 1 << endl;
28 
29     return 0;
30 }
View Code

 

B - Frodo and pillows(构造or二分)

题意: 给你n个床,m个枕头.要求每个床最少分配一个枕头. 同时相邻的床的枕头个数之差要小于等于1; 要求第k张床的枕头数最大; 求这个最大值是多少.

思路:类似金字塔一样的一层一层叠上去。这题还可以用二分。

技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int INF = 0x3f3f3f3f;
 4 const int maxn = 100 + 5;
 5 typedef long long LL;
 6 typedef pair<int, int>pii;
 7 
 8 int main()
 9 {
10     LL n, m, k;
11     while(cin >> n >> m >> k)
12     {
13         LL ans = 0;
14         m -= n, ans++;
15         LL leftlimit = k - 1, rightlimit = n - k;
16         LL left = 0, right = 0;
17         while(m > left + right)
18         {
19             ans ++;
20             m -= left + right + 1;
21             left = min(left + 1, leftlimit);
22             right = min(right + 1, rightlimit);
23             if(left == leftlimit && right == rightlimit)
24             {
25                 ans += m / n;
26                 break;
27             }
28         cout << ans << endl;
29     }
30 
31     return 0;
32 }
View Code

 

 

Codeforces Round #393 (Div. 2)

标签:water   ros   pillow   int   ide   ted   max   ret   src   

原文地址:http://www.cnblogs.com/luosuo10/p/6347867.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!