//
A Maximum Square :
#include<bits/stdc++.h> using namespace std; const int N=1e5+10; typedef long long ll; int arr[N]; int main() { int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&arr[i]); sort(arr+1,arr+1+n); int ans=0; for(int i=n;i>0;i--) ans=max(ans,min(arr[i],n-i+1)); printf("%d ",ans); } return 0; }
B1 Character Swap (Easy Version)
#include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <map> #include <vector> #include <set> #include <queue> #include <stack> #include <cmath> using namespace std; #define mem(s,t) memset(s,t,sizeof(s)) #define pq priority_queue #define pb push_back #define fi first #define se second #define ac return 0; #define ll long long #define cin2(a,n,m) for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j]; #define rep_(n,m) for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) #define rep(n) for(int i=1;i<=n;i++) #define test(xxx) cout<<" Test " <<" "<<xxx<<endl; #define TLE std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10); #define lc now<<1 #define rc now<<1|1 #define ls now<<1,l,mid #define rs now<<1|1,mid+1,r #define half no[now].l+((no[now].r-no[now].l)>>1) #define ll long long const int mxn = 1e6+5; ll n,m,k,ans,cnt,col; int a[mxn],b[27]; string str ,ch ; int main() { cin>>n; while(n--) { cin>>k; cin>>str>>ch; k = 0; memset(b,0,sizeof(b)); for(int i=0;i<str.size() && k<3;i++) { b[str[i]-'a']++; if(str[i]!=ch[i]) { a[++k]=i+1; } } if(k>=3 || k==1 ) cout<<"No"<<endl; else if(k==2) { if(str[a[1]-1] == str[a[2]-1] && ch[a[2]-1] == ch[a[1]-1] ) cout<<"Yes"<<endl; else cout<<"No"<<endl; } } return 0; }
B2 Character Swap (Easy Version) (来着聚聚)
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #include <list> #include <set> #include <map> #include <cctype> #include <string> #include <queue> #define mst(a,b) memset((a),(b),sizeof(a)) #define debug printf("debug ") #define INF 0x3f3f3f3f #define lson lef,mid,rt<<1 #define rson mid+1,rig,rt<<1|1 const int maxn=1e5+5; using namespace std; typedef long long ll; typedef unsigned long long ull; char str1[55],str2[55]; int cnt[30]; struct node{ int lef,rig; }; vector<node> ans; int main() { int t;scanf("%d",&t); while(t--){ ans.clear(); int n;scanf("%d",&n); scanf("%s",str1+1); scanf("%s",str2+1); bool flag=1;mst(cnt,0); for(int i=1;i<=n;i++){ cnt[str1[i]-'a']++; cnt[str2[i]-'a']++; } for(int i=0;i<30;i++){ if(cnt[i]&1){ flag=0;break; } } if(!flag){ puts("No"); }else{ puts("Yes"); for(int i=1;i<=n;i++){ if(str1[i]!=str2[i]){ for(int j=i+1;j<=n;j++){ if(str1[i]==str1[j]){ ans.push_back(node{j,i}); swap(str1[j],str2[i]); break; } if(str1[i]==str2[j]){ ans.push_back(node{j,j}); swap(str1[j],str2[j]); ans.push_back(node{j,i}); swap(str1[j],str2[i]); break; } } } } int sz=ans.size();printf("%d ",sz); for(int i=0;i<sz;i++){ printf("%d %d ",ans[i].lef,ans[i].rig); } } } return 0; }
https://www.cnblogs.com/Shallow-dream/p/11823678.html
D 0-1 MST