2.16 codeforce ABC

传送门

A:

 1 /**\
 2 思路:遍历最后一位即可 因为7个数一个循环,最后一位数必定出现7的倍数
 3 \**/
 4 #include <bits/stdc++.h>
 5 
 6 using namespace std;
 7 
 8 signed main()
 9 {
10     int _;
11     cin >> _;
12     while(_--)
13     {
14         int x;
15         cin>>x;
16         if(x%7==0)
17         {
18             cout<<x<<"\n";
19             continue;
20         }
21         x-=x%10;
22         for(int i = x;;i++){
23             if(i%7==0){
24                 cout<<i<<"\n";
25                 break;
26             }
27         }
28     }
29     return 0;
30 }

 

B:

/**\
思路:统计串中01的个数 
个数相等:是1的话 输出0, 不是1 ,就是个数-1
个数不相等:输出较小的个数就行了 
\**/
#include <bits/stdc++.h>

using namespace std;

string s;

signed main()
{
    int _;
    cin >> _;
    while(_--)
    {
        cin >> s;
        int a = 0, b = 0;
        for(auto c : s)
        {
            if(c == '0')a++;
            else b++;
        }
        // cout << a << " " << b << endl;
        if(a == b && a == 1)
        {
            puts("0");
            continue;
        }
        if(a != b)
        {
            cout << min(a, b) << "\n";
        }
        else cout<<a-1<<"\n";


    }
    return 0;
}

C:

 1 /**\
 2 思路:k 的 数字 2e5 我们暴力枚举每种情况就可以了
 3 只要自己承受的回合数 >= 怪兽能承受我的回合数
 4 hc/dm >= hm/dc (向下取整)
 5 \**/
 6 #include <bits/stdc++.h>
 7 #define int long long
 8 
 9 using namespace std;
10 
11 template <typename T> inline void read(T& t)
12 {
13     int f = 0, c = getchar();
14     t = 0;
15     while (!isdigit(c)) f |= c == '-', c = getchar();
16     while (isdigit(c)) t = t * 10 + c - 48, c = getchar();
17     if (f) t = -t;
18 }
19 bool check(int hc, int dc, int hm, int dm)
20 {
21     int len = (hc + dm - 1) / dm;
22     if(len  >= (hm+dc-1)/dc) return true;
23     return false;
24 }
25 int h1, d1, h2, d2, k, w, a;
26 
27 signed main()
28 {
29     int _;
30     read(_);
31 
32     while(_--)
33     {
34         int f = 0;
35         read(h1), read(d1), read(h2), read(d2), read(k), read(w), read(a);
36         for(int i = 0; i <= k; ++i)
37         {
38             int j = k - i;
39             int rh1 = h1 + i * a, rh2 = d1 + j * w;
40             if(check(rh1, rh2, h2, d2))
41             {
42                 f  = 1;
43                 break;
44             }
45 
46         }
47         if(f) puts("Yes");
48         else puts("No");
49 
50     }
51     return 0;
52 }

 

posted @ 2022-02-16 22:43  std&ice  阅读(57)  评论(0编辑  收藏  举报