Codeforces Round #594 (Div. 2) 题解

题目链接:https://codeforces.com/contest/1248

 

A - Integer Points

水题

#include<bits/stdc++.h>
using namespace std;
const int mx = 1e5+5;
typedef long long ll;
int a[mx],b[mx]; 
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n,m;
		scanf("%d",&n);
		ll c[2] = {0,0};
		ll d[2] = {0,0};
		for (int i=1;i<=n;i++) {
			scanf("%d",a+i);
			c[a[i]%2]++;
		}
		scanf("%d",&m);
		for (int i=1;i<=m;i++) {
			scanf("%d",b+i);
			d[b[i]%2]++;
		}
		printf("%lld\n",c[0]*d[0]+c[1]*d[1]);
	}
	return 0;
}

B - Grow The Tree

意思就是一半的和做一边,另一半的和做另一边,平方的话让一边越大越好就行了


#include<bits/stdc++.h>
using namespace std;
const int mx = 1e5+5;
typedef long long ll;
int a[mx],b[mx]; 
int main(){
	int n;
	scanf("%d",&n);
	int sum = 0;
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		sum += a[i];
	}
	sort(a+1,a+1+n);
	int beg = n / 2,ret = 0;
	for (int i=1;i<=beg;i++)
		ret += a[i];
	printf("%lld\n",1ll*ret*ret+1ll*(sum-ret)*(sum-ret));
	return 0;
}

C - Ivan the Fool and the Probability Theory

不难证明除了黑白交替的方块意外,其他的方块数都是取决于第一行的摆放方案,后面跟随第一行都摆放都是固定的。然后一行的dp方案只要记最后是连续两个一样的还是不一样的方案数就可以,另外行数对黑白交替的方案数的影响其实是一样的。

#include<bits/stdc++.h>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值