AtCoder Beginner Contest 055

A

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

typedef long long ll;
int main(){
	ll n;	scanf("%lld", &n);
	printf("%lld\n", n * 800 - n / 15 * 200);
	return 0;
}

B

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

typedef long long ll;
const int MOD = 1e9 + 7;

int main(){
	ll	n;	scanf("%lld", &n);
	ll sum = 1;
	for(ll i = 2; i <= n; ++i){
		sum = (sum * i) % MOD;
	}
	printf("%lld\n", sum);
	return 0;
}

C

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

typedef long long ll;
ll n, m;

int main(){
	scanf("%lld%lld", &n, &m);
	ll sum = 0;
	if(n >= m / 2){
		printf("%lld\n", m / 2);
		return 0;
	}
	sum = n;
	m = m - 2 * n;
	sum += m / 4;
	printf("%lld\n", sum);
	return 0;
}

D

這題枚舉四種情況就可以, 我枚舉1, 2號 是sheep還是wolf,  然後可以根據1, 2 號推出餘下所有的動物,, 最後檢查一下是否可以

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

typedef long long ll;
const int qq = 1e5 + 10;
ll n, m;
char str[qq];
int vis[qq];
bool judge(){
//	for(int i = 1; i <= n; ++i)
//		printf("%d ", vis[i]);
//	printf("\n");
	for(int i = 2; i < n; ++i)
		if(vis[i] == 1){
			if(str[i] == 'o'){
				if(vis[i + 1] != vis[i - 1])	return false;
			}else{
				if(vis[i + 1] == vis[i - 1])	return false;
			}
		}else{
			if(str[i] == 'o'){
				if(vis[i + 1] == vis[i - 1])	return false;
			}else{
				if(vis[i + 1] != vis[i - 1])	return false;
			}
		}
	if(vis[1] == 1){
		if(str[1] == 'o'){
			if(vis[2] != vis[n])	return false;
		}else{
			if(vis[2] == vis[n])	return false;
		}
	}else{
		if(str[1] == 'o'){
			if(vis[2] == vis[n])	return false;
		}else{
			if(vis[2] != vis[n])	return false;
		}
	}
	if(vis[n] == 1){
		if(str[n] == 'o'){
			if(vis[n - 1] != vis[1])	return false;
		}else{
			if(vis[n - 1] == vis[1])	return false;
		}
	}else{
		if(str[n] == 'o'){
			if(vis[n - 1] == vis[1])	return false;
		}else{
			if(vis[n - 1] != vis[1])	return false;
		}
	}
	return true;
}

void print(){
	for(int i = 1; i <= n; ++i)
		if(vis[i] == 1)	printf("S");
		else	printf("W");
	puts("");
}

int main(){
	scanf("%lld", &n);
	scanf("%s", str + 1);
	int flag = false;
	vis[1] = 1;
	vis[2] = 1;
	for(int i = 2; i < n; ++i)
		if(vis[i] == 1){
			if(str[i] == 'o')	vis[i + 1] = vis[i - 1];
			else				vis[i + 1] = (vis[i - 1] == 1 ? 0 : 1);
		}else{
			if(str[i] == 'x')	vis[i + 1] = vis[i - 1];
			else				vis[i + 1] = (vis[i - 1] == 1 ? 0 : 1);
		}
	flag = judge();
	if(flag == true){
		print();
		return 0;
	}
	vis[1] = 0;
	vis[2] = 0;
	for(int i = 2; i < n; ++i)
		if(vis[i] == 1){
			if(str[i] == 'o')	vis[i + 1] = vis[i - 1];
			else				vis[i + 1] = (vis[i - 1] == 1 ? 0 : 1);
		}else{
			if(str[i] == 'x')	vis[i + 1] = vis[i - 1];
			else				vis[i + 1] = (vis[i - 1] == 1 ? 0 : 1);
		}
	flag = judge();
	if(flag == true){
		print();
		return 0;
	}
	vis[1] = 1;
	vis[2] = 0;
	for(int i = 2; i < n; ++i)
		if(vis[i] == 1){
			if(str[i] == 'o')	vis[i + 1] = vis[i - 1];
			else				vis[i + 1] = (vis[i - 1] == 1 ? 0 : 1);
		}else{
			if(str[i] == 'x')	vis[i + 1] = vis[i - 1];
			else				vis[i + 1] = (vis[i - 1] == 1 ? 0 : 1);
		}
	flag = judge();
	if(flag == true){
		print();
		return 0;
	}
	vis[1] = 0;
	vis[2] = 1;
	for(int i = 2; i < n; ++i)
		if(vis[i] == 1){
			if(str[i] == 'o')	vis[i + 1] = vis[i - 1];
			else				vis[i + 1] = (vis[i - 1] == 1 ? 0 : 1);
		}else{
			if(str[i] == 'x')	vis[i + 1] = vis[i - 1];
			else				vis[i + 1] = (vis[i - 1] == 1 ? 0 : 1);
		}
	flag = judge();
	if(flag == true){
		print();
		return 0;
	}
	printf("-1\n");
}


你可能感兴趣的:(Atcoder)