The 2021 Sichuan Provincial Collegiate Programming Contest
阿新 • • 發佈:2021-10-17
思路:
可以打表,但不如列舉快,列舉就從1到6兩重迴圈,由於1,3 3,1算一種,所以第二重直接從i開始就可以
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <set> #include <vector> #include <map> #include<unordered_set> #include <unordered_map> #define x first #define y second #define IOS ios::sync_with_stdio(false);cin.tie(0); using namespace std; typedef long long LL; typedef pair<int, int> PII; const int N = 100010, MOD = 1000000007, INF = 0x3f3f3f3f; int main() { IOS; int T; cin>> T; while(T -- ) { int k; cin >> k; int res = 0; for (int i = 1; i <= 6; i ++ ) for (int j = i; j <= 6; j ++ ) if(i + j == k) res++; cout << res << endl; } return 0; }
思路:
由於m太大所以必然不能遍歷m次操作,我們可以把2n次操作算作一輪,然後可以把這m次操作分成若干輪,找找有多少次這樣的2n輪,最後湊不成一輪的多出來的幾次操作單獨遍歷處理就可以了
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <set> #include <vector> #include <map> #include <unordered_set> #include <unordered_map> #define x first #define y second #define IOS ios::sync_with_stdio(false);cin.tie(0); using namespace std; typedef long long LL; typedef pair<int, int> PII; const int N = 100010, MOD = 1000000007, INF = 0x3f3f3f3f; PII pot[N]; bool st[N]; int main() { IOS; int T; cin >> T; while(T -- ) { int n, k, m; cin >> n >> k >> m; memset(st, 0, sizeof st); for (int i = 0; i < n; i ++ ) { cin >> pot[i].first; pot[i].second = 0; } for (int i = 0; i < 2 * n; i ++ ) { int idx = i % n; if(st[pot[idx].first]) { st[pot[idx].first] = 0; pot[idx].second++; } else st[pot[idx].first] = 1; } int tmp = m / (2 * n);//m中有多少個2n for (int i = 0; i < n; i ++ ) pot[i].second *= tmp; int mod = m % (2 * n);//多出來的幾個單獨處理 for (int i = 0; i < mod; i ++ ) { int idx = i % n; if (st[pot[idx].first]) { st[pot[idx].first] = 0; pot[idx].second++; } else st[pot[idx].first] = 1; } for (int i = 0; i < n - 1; i ++ ) cout << pot[i].second << ' '; cout << pot[n - 1].second << endl; } return 0; }
思路:
先手的所有出牌情況都不會影響結果,只能是後手才會影響,而後手會優先考慮贏的情況,然後是平局,最後才是輸的情況,所以依次判斷先手石頭剪刀布的後手情況即可,記得開long long
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <set> #include <vector> #include <map> #include <unordered_set> #include <unordered_map> #define int LL #define x first #define y second #define IOS ios::sync_with_stdio(false);cin.tie(0); using namespace std; typedef long long LL; typedef pair<int, int> PII; const int N = 100010, MOD = 1000000007, INF = 0x3f3f3f3f; PII pot[N]; bool st[N]; signed main() { IOS; int T; cin >> T; while(T -- ) { int br, bp, bs, dr, dp, ds; cin >> br >> bp >> bs >> dr >> dp >> ds; int res = 0; if(br) { if(dp && br)//贏 { int tmp = min(dp, br); res += tmp; dp -= tmp; br -= tmp; } if(dr && br)//平 { int tmp = min(dr, br); dr -= tmp; br -= tmp; } if(ds && br)//輸 { int tmp = min(ds, br); res -= tmp; ds -= tmp; br -= tmp; } } if (bp) { if (ds && bp) //贏 { int tmp = min(ds, bp); res += tmp; ds -= tmp; bp -= tmp; } if (dp && bp) //平 { int tmp = min(dp, bp); dp -= tmp; bp -= tmp; } if (dr && bp) //輸 { int tmp = min(dr, bp); res -= tmp; ds -= tmp; br -= tmp; } } if (bs) { if (dr && bs) //贏 { int tmp = min(dr, bs); res += tmp; dr -= tmp; bs -= tmp; } if (ds && bs) //平 { int tmp = min(ds, bs); ds -= tmp; bs -= tmp; } if (dp && bs) //輸 { int tmp = min(dp, bs); res -= tmp; dp -= tmp; bs -= tmp; } } cout << res << endl; } return 0; }
E - Don't Really Like How The Story Ends
思路:
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <set> #include <vector> #include <map> #include <unordered_set> #include <unordered_map> #define int LL #define x first #define y second #define IOS ios::sync_with_stdio(false);cin.tie(0); using namespace std; typedef long long LL; typedef pair<int, int> PII; const int N = 100010, MOD = 1000000007, INF = 0x3f3f3f3f; int n, m; int nxt, res; vector<int> g[N]; //u表示當前點序號,nxt表示下一個要到的點的序號 void dfs(int u) { if(u == n + 1) return; for (auto x : g[u]) { if(x < nxt) continue; while(x >= nxt) { if(x == nxt) nxt++, dfs(nxt - 1);//nxt指向下一個要到的點,nxt-1表示上次的nxt變成了現在的點,並dfs這個點 else if(x > nxt) res++, nxt++, dfs(nxt - 1); } } } signed main() { IOS; int T; cin >> T; while(T -- ) { for (int i = 1; i <= n; i ++ ) g[i].clear(); cin >> n >> m; while(m -- ) { int a, b; cin >> a >> b; g[a].push_back(b), g[b].push_back(a); } g[1].push_back(n + 1);//為了方便讓1和n+1相連 for (int i = 1; i <= n; i ++ ) sort(g[i].begin(), g[i].end()); nxt = 2, res = 0; dfs(1); cout << res << endl; } return 0; }