令我感到非常自闭的一场div3
反正没打完就溜了
思维
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #pragma GCC optimize(2) #define mm(i,v) memset(i,v,sizeof i); #define mp(a, b) make_pair(a, b) #define one first #define two second using namespace std; typedef long long ll; typedef pair<int, int > PII; const int N = 1e6 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f; int q; ll a, b, n, s; ll tmp1, tmp2; int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // cin.tie(0); // cout.tie(0); // ios::sync_with_stdio(0); cin >> q; while (q--) { cin >> a >> b >> n >> s; tmp1 = s / n; tmp2 = s % n; if (tmp1 <= a) { if (b >= tmp2) puts("YES"); else puts("NO"); } else { if (a * n + b >= s) puts("YES"); else puts("NO"); } } }
贪心,具体怎么贪忘了,前段时间写的
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #pragma GCC optimize(2) #define mm(i,v) memset(i,v,sizeof i); #define mp(a, b) make_pair(a, b) #define one first #define two second using namespace std; typedef long long ll; typedef pair<int, int > PII; const int N = 110, mod = 1e9 + 9, INF = 0x3f3f3f3f; int q, n, idx, sum, pos; int a[N]; bool vis[N]; void Get() { idx = INF; for (int i = 1; i <= n; ++i) { if (vis[i]) continue; if (a[i] < idx) { idx = a[i]; pos = i; } } return ; } int main() { cin >> q; while (q--) { mm(vis, 0); cin >> n; for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); } int i, j; sum = 0; while (sum < n) { Get(); printf("%d ", idx); vis[pos] = 1; sum ++; while (1) { pos --; if (vis[pos] == 0 || pos < 1) break; } while (1) { pos --; if (vis[pos] == 0 || pos < 1) break; } // cout << "pos :" << pos << endl; for (j = 1; j <= pos; ++j) { if (!vis[j]) { printf("%d ", a[j]); vis[j] = 1; sum ++; } } } printf(" "); } }
也是一道贪心,但是没写出来,WA来WA去的WA到怀疑人生
贴一个当时网上找的代码
#include<bits/stdc++.h> using namespace std; const int N = 2e5 + 11; int c[N],ans[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,d; cin>>n>>m>>d;//n是宽度,m是板子数目,d是可以最多跳多远 int pos=0; for (int i=1; i<=m; i++) { pos+=d;//每次跳最远 int l; cin>>l; pos+=l-1; c[i]=l;//记录板子长度 } pos+=d;//最后再跳一次 if (pos<n+1) {//如果跳不过去 cout<<"NO";//就输出NO return 0; } cout<<"YES "; pos=0; int sum=0; for (int i=1; i<=m; i++) sum+=c[i];//板子总长度 for (int i=1; i<=m; i++) { if (pos+d+sum-1<=n) pos+=d; else pos=n-sum+1; for (int j=pos; j<=pos+c[i]-1; j++) ans[j]=i; pos+=c[i]-1; sum-=c[i]; } for (int i=1; i<=n; i++) cout<<ans[i]<<" "; }
感觉这场貌似反而D比较简单?
还是贪心,就尽量把0往前面挪
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <queue> #pragma GCC optimize(2) #define mm(i,v) memset(i,v,sizeof i); #define mp(a, b) make_pair(a, b) #define one first #define two second using namespace std; typedef long long ll; typedef pair<int, int > PII; const int N = 1e6 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f; ll n, q, k, ans, idx; char s[N]; queue <ll> ss; int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // cin.tie(0); // cout.tie(0); // ios::sync_with_stdio(0); cin >> q; while (q--) { while (!ss.empty()) ss.pop(); cin >> n >> k; scanf("%s", s + 1); for (int i = 1; i <= n; ++i) { if (s[i] == '0') { ss.push(i); } } ans = 0, idx = 1; while (!ss.empty()) { int x = ss.front(); ss.pop(); if (ans + x - idx > k) { swap(s[x], s[x + ans - k]); break; } ans += (x - idx); swap(s[idx++], s[x]); } printf("%s ", s + 1); } } /* 1 7 9 1111100 */