Codeforces Round #534

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/happy_Du/article/details/86607921

(蒟蒻我又回来了,这次备战ACM,此生无悔入信竞)

题目链接:点我跳转

A Splitting into digits

题目大意:把一个数分成几个十以内数的和,又要求这几个数之间的差尽可能小
题目分析:那不就是把一个数拆成几个相等的数嘛。。。

#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int n;
	cin>>n;
	for(int i=9;i>0;i--){//从9到1找哪个数能整除
		if(n%i == 0){
			cout<<n/i<<"\n";
			for(int j=0;j<n/i;j++)
				cout<<i<<" ";
			return 0;
		}
	}
	return 0;
}

原谅我的无知与愚昧,其实 直接输出n个1 居然就完事了。。。

B Game with string

题目大意:两个人轮流从一个字符串里面删去两个连续相同的字母,如果轮到谁的时候没得删了就输了
题目分析:如此简单的模拟水题,如果我能一眼就看到字母,不是字符串就好了。

#include<iostream>
#include<cstdio>
#include<stack>
#include<string>
#include<cstring>

using namespace std;

int main(){
	string ss;
	cin>>ss;
	int ss_l = ss.size(),r = 0;
	
	stack<char> sta;
	
	for(int i=0;i<ss_l;i++){
		char ch = ss[i];
		if(!sta.empty() && sta.top() == ch){
			sta.pop();
			r++;
		}else sta.push(ch);
		
	}
	cout<<((r&1)?"YES":"NO");
	return 0;
}

C Grid game

题目大意:有点像俄罗斯方块,有一堆1×2和2×1的条,放到4×4的网格中,填满一行或一列就消掉
题目分析:我简直了,,,想了很神奇的算法,写了100多行,结果很简单啊,竖着的从(1,1)往下填,横着的从(4,3)往左填,就完了。。。

#include<iostream>
#include<cstdio>
#include<stack>
#include<string>
#include<cstring>

using namespace std;

int main(){
	string ss;
	cin>>ss;
	int ssl = ss.size(),r = 0,h = 0;
	for(int i=0;i<ssl;i++){
		if(ss[i] == '0'){
			if(r)printf("3 1\n"),r = 0;
			else printf("1 1\n"),r = 1;
		}else{
			if(h)printf("4 1\n"),h = 0;
			else printf("4 3\n"),h = 1;
		}
	}
	return 0;
}

事实证明我是真的菜,以后还要多加练习才是。。。

猜你喜欢

转载自blog.csdn.net/happy_Du/article/details/86607921
今日推荐