Codeforces Round #813 (Div. 2)
题意:
#include<bits/stdc++.h> using namespace std; const int maxn = 120; int a[maxn]; void solve() { int n,k; cin >> n >> k; int cnt = k; for(int i = 1; i <= n; i ++) { cin >> a[i]; if(i <= k && a[i] <= k) cnt --; } cout << cnt << "\n"; } int main() { int t; cin >> t; while(t --) { solve(); } return 0; }
题意:确定序列 P{p1, p2 ... pn}中 1~n 的排列顺序,使得 lcm(1,p1)+lcm(2,p2)+…+lcm(n,pn) 最大。 lcm:最小公倍数
#include<bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; stack<int> s; if(n % 2 == 0) { for(int i = n; i >= 1; i --) { if(i % 2 == 0) s.push(i - 1); else s.push(i + 1); } } else { for(int i = n; i > 1; i --) { if(i % 2 == 0) s.push(i + 1); else s.push(i - 1); } s.push(1); } while(!s.empty()) { cout << s.top() << " "; s.pop(); } cout << "\n"; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; cin >> t; while(t --) { solve(); } return 0; }
·1712C - Sort Zero
题意:
标签:lcm,题意,int,Codeforces,--,solve,push,Div,813 From: https://www.cnblogs.com/coding-inspirations/p/16584854.html