Codeforces Beta Round #95

A - cAPS lOCK

如果字符串全部是大写或者除首字母外都大写,那么改变整个串的大小写,大写转小写,小写转大写。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

char a[1000];
int main()
{
	while(gets(a)){
		int i;
		for(i = 1; a[i]; ++i){
			if(a[i] >= 'a' && a[i] <= 'z'){
				break;
			}
		}
		if(a[i] == 0){
			for(i = 0; a[i]; ++i){
				if(a[i] >= 'A' && a[i] <= 'Z'){
					printf("%c",a[i] + 32);
				}
				else{
					printf("%c",a[i] - 32);
				}
			}
			puts("");
		}
		else{
			puts(a);
		}

	}
	return 0;
}

B - Opposites Attract

要求找到A和B的和为0的所有组合数。直接hash统计。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

long long xhash[21];
int main()
{
	int n;
	while(scanf("%d", &n) != EOF){
		int i, t;
		memset(xhash, 0, sizeof(xhash));
		for(i = 0; i < n; ++i){
			scanf("%d", &t);
			xhash[t + 10]++;
		}
		long long ans = 0;
		for(i = 0; i < 10; ++i){
			ans = ans + xhash[i] * xhash[20 - i];
		}
		ans = ans + xhash[10] * (xhash[10] - 1) / 2;
		printf("%I64d\n", ans);
	}
	return 0;
}

C - The World is a Theatre

从n个男生中选取至少4个男生,从m个女生中至少选取1个女生,选取的总人数为t的所有组合数。暴力。

#include <iostream>
#include <cstdio>
using namespace std;
#define LL long long

LL com(LL n, LL r){// return C(n, r)
	if( n-r > r ) r = n-r; // C(n, r) = C(n, n-r)
	LL  i, j, s = 1;
	for( i=0, j=1; i < r; ++i ){
		s *= (n-i);
		for( ; j <= r && s%j == 0; ++j ) s /= j;
	}
	return s;
}

int main(){
	LL n, m, t;
	while(scanf("%I64d %I64d %I64d", &n, &m, &t) != EOF){
		LL i, ans;
		ans = 0;
		for(i = 1; t - i >= 4; ++i){
			ans += com(n, t - i) * com(m, i);
		}

		printf("%I64d\n", ans);
	}
	return 0;
}

D、E、F暂时不会

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值