A. Gellyfish and Tricolor Pansy
翻譯:
????????水母和小花在玩一個叫 “決斗 ”的游戲。
????????水母有 a HP,花花有 b HP。
????????它們各有一個騎士。水母的騎士有 c HP,而花花的騎士有 d HP。
????????他們將進行一輪游戲,直到其中一方獲勝。對于 k=1、2、... 的順序,他們將執行以下操作:
- 如果 k 為奇數,且水母的騎士活著:
- 如果 b≤0 則水母獲勝。或者,水母的騎士可以攻擊花花的騎士并將 d
- ?如果 d≤0,花花的騎士死亡。
- 如果 k 為偶數,且花花的騎士活著:
- 如果a≤0,花花獲勝。或者,花花的騎士可以攻擊水母的騎士并將 c
- ?如果 c≤0 海蜇的騎士死亡。
????????作為世界上最聰明的人之一,你想在比賽前告訴他們誰會贏。假設雙方都以最佳狀態下棋。
可以證明對局永遠不會以和棋結束。也就是說,一方擁有在有限步數內結束對局的策略。
思路:
????????只要將敵方的任意一人殺死,即可獲勝。(模擬,貪心)
實現:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;void solve(){ll a,b,c,d;cin>>a>>b>>c>>d;if (min(a,c)>=min(b,d)){cout<<"Gellyfish"<<endl;}else{cout<<"Flower"<<endl;}
}int main(){// 關閉輸入輸出流同步ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);// 不使用科學計數法// cout<<fixed;// 四舍五入中間填保留幾位小數,不填默認// cout.precision();int t=1;cin>>t;while (t--) solve();return 0;
}
B. Gellyfish and Baby's Breath
翻譯:
????????Flower 給 Gellyfish 提供了 [0,1,...,n-1]的兩個排列?:
和
。
????????現在,Gellyfish 希望通過以下方法計算一個數組
?的計算方法如下:
- 對于所有 i (0≤i≤n-1),
。
????????但由于水母很懶,你必須幫她算出 r 的元素。
????????由于 r 的元素非常大,你只需輸出 r 的元素 modulo 998244353。
思路:
????????2的i次從二進制數來看2^i+2^j與其他同類型的比較,一般由i,j中的較大部分即可。
? ? ? ? 即我們在遍歷r中,記錄p,q最大值的下標,再通過比較兩者及其對應的qp值大小,可得到最大值。(位運算)
實現:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MX = 1e6+10;
const ll mod = 998244353;
vector<ll> pow_2(MX,1);
void solve(){int n;cin>>n;vector<ll> a(n),b(n),ans(n);for (auto &i:a) cin>>i;for (auto &i:b) cin>>i;ll ind_a_max = 0,ind_b_max = 0;for (int i=0;i<n;i++){// updateif (a[i]>a[ind_a_max]) ind_a_max = i;if (b[i]>b[ind_b_max]) ind_b_max = i;if (a[ind_a_max]>b[ind_b_max] || (a[ind_a_max]==b[ind_b_max] && b[i-ind_a_max]>a[i-ind_b_max])){ans[i] = (pow_2[a[ind_a_max]]+pow_2[b[i-ind_a_max]])%mod;}else{ans[i] = (pow_2[a[i-ind_b_max]]+pow_2[b[ind_b_max]])%mod;}}for (int i=0;i<n;i++){cout<<ans[i]<<" \n"[i==n-1];}
}int main(){// 關閉輸入輸出流同步ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);// 不使用科學計數法// cout<<fixed;// 四舍五入中間填保留幾位小數,不填默認// cout.precision();// initiationfor (int i=1;i<MX;i++){pow_2[i] = (pow_2[i-1]*2)%mod;}int t=1;cin>>t;while (t--) solve();return 0;
}
C. Gellyfish and Flaming Peony
翻譯:
????????水母討厭數學問題,但她必須完成數學作業:
????????給水母一個由 n 個正整數 a1、a2......、an 組成的數組。
????????她需要進行以下兩步運算,直到 a 的所有元素都相等為止的所有元素都相等:
- 選擇滿足 1≤i,j≤n 和 i≠j 的兩個索引 i、j。
- 用 gcd(ai,aj) 代替 ai。
????????現在,水母向你詢問實現目標所需的最少運算次數。
????????可以證明,水母總能實現她的目標。
思路:
? ? ? ? 最后a數組的值每個都必定是
。那么先用最小的次數將一個值變為最終值(廣度優先搜索),再通過這個值,與其他不同的值gcd,即可最快完成目標。(數學,bfs)
實現:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;
void solve(){int n,mx=0;cin>>n;vector<int> a(n);for (int&i:a) cin>>i;int res = a[0];for (int& i:a) res = gcd(res,i),mx = max(mx,i);// bfs:查找最小得到res的集合vector<int> cnt(mx+1,-1);queue<array<int,2>> pq;for (int &i:a){pq.push({i,0});}while (!pq.empty()){auto[now,step] = pq.front();pq.pop();if (cnt[now]!=-1) continue;cnt[now] = step;if (now==res){break;}for (int &i:a){int new_gcd = gcd(i,now);if (cnt[new_gcd]==-1){pq.push({new_gcd,step+1});}}}int need = cnt[res],ans = 0;for (int &i:a) ans+=(res!=i);if (need>0) ans+=need-1;cout<<ans<<"\n;
}int main(){// 關閉輸入輸出流同步ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);// 不使用科學計數法// cout<<fixed;// 四舍五入中間填保留幾位小數,不填默認// cout.precision();int t=1;cin>>t;while (t--) solve();return 0;
}
之后補題會在此增加題解。????
話說看我題解的有真人不?