"HKUST Xunfei Cup" 18th Shanghai University Programming League Spring Competition and College Network Friendly Match D. Largest Character Set

D. Maximum character set

Topic link-D. The maximum character set
Insert picture description here
Insert picture description here
Insert picture description here
solution ideas

  • Need special judgment n = 1 n=1 and n = 2 n=2 situation, n = 1 n=1 , the collection can be {1} or {0}, n = 2 n=2 , the set can be {0, 11} or {1, 00}
  • n > 2 n>2 o'clock, the elements in the collection should all have a structure of 100 ... 001, ie {11, 101, 1001, ...}
  • See the code for specific operations

Attach the code

//#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
const double PI=acos(-1.0);
const double e=exp(1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=2e5+10;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long ull;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	int n;
	cin>>n;
	if(n==1){
		cout<<1<<endl<<1<<endl;
		return 0;
	}
	if(n==2){
		cout<<2<<endl;
		cout<<0<<endl<<11<<endl;
		return 0;
	}
	cout<<n-1<<endl;
	for(int i=2;i<=n;i++){
		cout<<1;
		for(int j=2;j<i;j++)
			cout<<0;
		cout<<1<<endl;
	}
	return 0;
}
Published 183 original articles · praised 38 · 20,000+ views

Guess you like

Origin blog.csdn.net/Fiveneves/article/details/105609298