首页 > 代码库 > Codeforces Round #393 (Div. 2)

Codeforces Round #393 (Div. 2)

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)