Codeforces Round #758 (Div.1 + Div. 2)

Codeforces Round #758 (Div.1 + Div. 2) Problem A & Problem B & (Problem C)

A. Find Array

从来都没有见过一个如此水的 Div 1 A题 就是让你从小到大的输出n个数字
唯一要注意的就是a[i]的取值范围

#include
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		for(int i=n;i<n+n;i++){
			cout<<i;
			cout<<' '; 
		}
		cout<<endl;
	}
	return 0;
}

B. Build the Permutation

给出n,a,b 要求输出n个数,并且有a个是a[i]a[i+2]
有b个是b[i]>b[i+1] 史上最详细注释来临!!

#include 
using namespace std;
int a,b,n;
void solve(){
    cin>>n>>a>>b;
    if(abs(a-b)>1||a+b>n-2){//see 5 3 4 2 as an example
    //there are four numbers and a eauals to 1 and b equals to 1 so a+b can only be equal or smaller than n-2 ans 
	//and as for abs(a-b)>1 see example if abs(a-b)==1   5 3 4  right now b equals to 1  and 1 2 3 will allow a to equal to zero
	//and as for abs(a-b)>1 see example if abs(a-b)==2   5 3 4 1 2 "5 3 4" b equals to 1 and with "4 1 2" b will add one and turn to two
	//but in this case a equals to one as well see "3 4 1" so abs(a-b)!=2  (shit,that's hard to explain_lol)
        cout<<-1<<endl;
        return;
    }
    vector<int>aa(n+10);//vector is just like a interger sequence but easier to change
    for(int i=1;i<=n;i++) aa[i]=i;
    int l=1;
    if(a<b) l=1;//this means that you need one extra small one than the bigger ones
    else if(a==b) l=2;//this means that it's all the same
    else l=n-2*a+1;//this means that you need oen extra big one than the smaller ones
    /*
    		example if you can't understand the whole l process
    see you right now have n=4 and aa is  1 2 3 4
    
    1. if you need an extra small one you swap aa[1] and aa[1+1] and so on
    	which you gets  2 1 3 4 (remember the fact that you need to make sure that i is smaller than max(a,b))
    2. if you need a to be the same as b you swap aa[2] and aa[2+1] and so on
    	which you gets 1 3 2 4
    3. if you need an extra big one you swap aa[3] and aa[4] and so one 
		which you gets 1 2 4 3
		
	(THIS SHIT IS REALLY HARD TO EXPLAIN "ARE YOU SURE THAT YOU WON'T GIVE ME A LIKE BUTTON?" 
    */
    for(int i=0;i<max(a,b);i++){
        swap(aa[l],aa[l+1]);
        l+=2;
    }
    for(int i=1;i<=n;i++) cout<<aa[i]<<' ';
	cout<<endl;
}
int main(){
    int T;
	cin>>T;
    while(T--) solve();
    return 0;
}

你要是还不给赞的话我就脑梗了!现在早上1:04分打卡(24小时后上C!!)
有问题问我P.S.博主最帅!

你可能感兴趣的:(Codeforces,题解,算法)