Codeforces Round #511 (Div. 2)

又到了摸鱼的时候了23333

A. Little C Loves 3 I

题意:给一个数,分解为不被3整除的3个数

题解:构造,如果这个数被3整除,就构造为1,1,n-2;否则构造为1,2,n-3

 1 class Solution(object):
 2     def run(self):
 3         n = int(input())
 4         if n % 3 == 0:
 5             print(1, 1, n - 2)
 6         else:
 7             print(1, 2, n - 3)
 8     
 9 if __name__ == '__main__':
10     Solution().run()
View Code

B. Cover Points

题意:用一个直角边为xy轴的等腰三角形覆盖坐标系上的点,问直角边长度

题解:不是等腰还有点意思,等腰就是大水题

 1 class Solution(object):
 2     def run(self):
 3         n = int(input())
 4         res = 0
 5         for _ in range(n):
 6             p = [int(x) for x in input().split(' ')]
 7             x, y = p[0], p[1]
 8             res = max(res, x + y)
 9         print(res)
10     
11 if __name__ == '__main__':
12     Solution().run()
View Code

C. Enlarge GCD

题意:从n个数中去掉x个,使GCD严格增大,求x的最小值

题解:将所有数的因子计数,记做cnt[],cnt[k] 表示有因子 k 的数的个数;很显然,当 k0 为所有数的gcd时,cnt[k0] 应该为 n;不难想出,留下的数的个数应该为 cnt[] 中第二大的那一个,Sure,第一大的是 cnt[k0] = n

Python读入就超时了 TvT

 1 #include <iostream>
 2 #include <vector>
 3 #include <cmath>
 4 
 5 std::vector<int> a((int)3e5+1), cnt((int)2e7);
 6 
 7 int main()
 8 {
 9     int n, mx = -1, mxx = -1;
10     std::cin >> n;
11     for (auto i = 0; i < n; i++)
12     {
13         std::cin >> a[i];
14         mxx = std::fmax(mxx, a[i]);
15         for (auto j = 1; j * j <= a[i] && n * j < (int)1.5e7 + 1; j++)
16             if (a[i] % j == 0)
17             {
18                 cnt[j]++;
19                 if (j * j != a[i])
20                     cnt[a[i] / j]++;
21             }
22     }
23     for (auto i = 2; i <= mxx; i++)
24         if (cnt[i] < n)
25             mx = std::fmax(mx, cnt[i]);
26     if (mx > 0)
27         std::cout << n - mx << std::endl;
28     else
29         std::cout << -1 << std::endl;
30     return 0;
31 }
View Code

D. Little C Loves 3 II

摸了

猜你喜欢

转载自www.cnblogs.com/hexsix/p/9690399.html