Try   HackMD

Codeforces 1407A. Ahahahahahahahaha

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

#include <bits/stdc++.h> using namespace std; void solve(){ int n; cin>>n; vector<int> cnt(2); for(int i=0;i<n;++i){ int a; cin>>a; cnt[a]++; } if(cnt[0]>=n/2){//0>1 cout<<n/2<<endl; for(int j=0;j<n/2;++j){ cout<<0<<" "; } cout<<endl; } else{//1>0 n=n-cnt[0]; if(n%2==1)--n; cout<<n<<endl; for(int j=0;j<n;++j){ cout<<1<<" "; } cout<<endl; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int T; cin>>T; while(T--) solve(); }

思路很簡單:允許砍n/2的元素,且全部只有0跟1,只要0個數>1個數那就把1全砍了剩下0絕對符合,反之把0全砍了且讓1個數為偶數就能保證a1-a2+a3-a4+=0。