A. Prime Minister(模拟)
题目链接:codeforces 1178A
题意:
Alice有一个政党a[1],现在要拉拢其他政党,要求,其他政党的人数严格小于他的政党人数的1/2,如果他最后的总人数大于全部人数的 1/2 , 输出他总共有多少个政党及下标
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[105], b[105];
int main(){
int n;
cin >> n;
int sum = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
sum += a[i];
}
int ans = a[1], num = 1;
for(int i = 2; i <= n; i++){
if(ans * 2 > sum){
break;
}
if(a[i] * 2 <= a[1]){
ans = ans + a[i];
b[num] = i;
num++;
}
}
if(ans * 2 <= sum){
cout << 0 << endl;
}
else{
cout << num << endl << 1;
for(int j = 1; j < num; j++){
cout << " " << b[j];
}
cout << endl;
}
return 0;
}
C Tiles(思维)
题目链接:codeforces 1178C
题意 :用如图所示的地板铺满整个地板,要求颜色相同的部分不能相邻 ,求有多少种方法

解题思路:
可以先画图找规律,发现在第一行或第一列,由于受前面地板的影响,后面的地板只有两种放法。
在之后的行或列,受前一行和前一列的影响,有4种放法
#include <iostream>
using namespace std;
const int MOD = 998244353;
int main() {
int R, C;
while(cin >> R >> C){
int ans = 1;
while(R--){
ans = ans * 2 % MOD;
}
while(C--){
ans = ans * 2 % MOD;
}
cout << ans % MOD << endl;
}
return 0;
}
485

被折叠的 条评论
为什么被折叠?



