Codeforces Round #511 (Div. 2)
阿新 • • 發佈:2018-09-22
elif 否則 int gcd pytho codeforce 技術 hide 個數
又到了摸魚的時候了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 ifView Code__name__ == ‘__main__‘: 10 Solution().run()
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(‘View Code‘)] 7 x, y = p[0], p[1] 8 res = max(res, x + y) 9 print(res) 10 11 if __name__ == ‘__main__‘: 12 Solution().run()
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
題意:在一個n*m的棋盤裏,盡可能多地放入曼哈頓距離為3的棋子對,問最多能放幾個棋子
題解:分類討論,然後總結一下,這題相當水
1 class Solution(object): 2 def run(self): 3 n, m = [int(x) for x in input().split()] 4 if n > m: 5 n, m = m, n 6 res = (n * m) // 2 7 if n == 1 and (m + 1) % 6 // 3: 8 res -= 1 9 elif n == 2: 10 if m == 2: 11 res = 0 12 elif m == 3: 13 res = 2 14 elif m == 7: 15 res = 6 16 print(res * 2) 17 18 if __name__ == ‘__main__‘: 19 Solution().run()View Code
E
摸了
Codeforces Round #511 (Div. 2)