Codeforces Round #535 (Div. 3)A,B,C,D,E1,E2,F

传送门
A. Two distinct points
解题思路:只要考虑左右端点即可,在简单讨论一下。代码如下

#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; using namespace std; int main() { std::ios::sync_with_stdio(0); int q; cin >> q; while (q--) { int l1, r1, l2, r2; cin >> l1 >> r1 >> l2 >> r2; if (l1 == r2) cout << r1 << " " << l2 << endl; else cout << l1 << " " << r2 << endl; } return 0; }

B. Divisors of Two Integers
解题思路:因子中最大的mx1肯定是其中一个数,然后在能被mx1整除且数量>1或者不能被mx1整除中在找最大的数mx2
#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll inf=0x3f3f3f3f; const int maxn=130; ll n,mx1=-inf,mx2=-inf,tp; map m; int main(){ std::ios::sync_with_stdio(0); cin>>n; for(int i=1; i<=n; ++i){ cin>>tp; m[tp]++; mx1=max(tp,mx1); } for(auto it=m.begin(); it!=m.end(); ++it){ ll num=it->first,cnt=it->second; if((cnt==1 && mx1%num!=0) || cnt>1){ mx2=max(num,mx2); } } cout<

C. Nice Garland
解题思路:相同的字符距离要是3的倍数,可得只要前三个字符固定了之后,后面就必须如此排列,不然不可能满足条件,例如RGB那后面必须是R没有选择,所以只需要"RGB","RBG","BGR","BRG","GBR","GRB"都讨论一下。
#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll inf=0x3f3f3f3f; using namespace std; string tmp[]= {"RGB","RBG","BGR","BRG","GBR","GRB"}; int ans[10]; int main() { std::ios::sync_with_stdio(0); int n; cin>>n; string s,res; cin>>s; map vis; int cnt = 0; if(n<3) { if(n==1) res = s; else { if(s[0]==s[1]) { if(s[0]=='R') s[1] = 'B'; if(s[0]=='G') s[1] = 'R'; if(s[0]=='B') s[1] = 'G'; res = s; cnt = 1; } } cout<
D. Diverse Garland
解题思路:把C改成了相邻的不能相同,先处理连续3个相同的,再处理连续两个相同的,代码还是比较繁琐的,
#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll inf=0x3f3f3f3f; const int maxn=2e5+50; int n; char st[maxn]; int main() { scanf("%d%s",&n,st); int ans=0; for(int i=1; i


E1. Array and Segments (Easy version)
E2. Array and Segments (Hard version)
戳这里
F. MST Unification
戳这里





【Codeforces Round #535 (Div. 3)A,B,C,D,E1,E2,F】

    推荐阅读