A. Prime Minister: http://codeforces.com/contest/1178/problem/A
题意:
Alice要搞选举当首相,自然要把人拉到他这边了,大家都知道选举最稳的是什么,当然是要超过总人数的一半了(注意是超过)。现在Ailce拉人,但是拉人也有拉人的规则。
1. Alice拉的别的团队的人数不能超过自己团队的一半
2. 想要选举成功,Alice最后团队的总人数要超过总人数的一半
问Alice能否选举成功?
分析:
直接暴力循环,能拉就拉,一旦超过超过总人数的一般就终止。
code:
#include <bits/stdc++.h>
using namespace std;
int a[100+7];
vector<int> ve;
int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
int sum = 0;
for(int i=0; i<n; i++)
{
scanf("%d", &a[i]);
sum += a[i];
}
ve.clear();
int alice = a[0];
ve.push_back(0);
for(int i=1; i<n; i++)
{
if(alice * 2 > sum)
break;
if(a[i]*2 <= a[0])
{
alice += a[i];
ve.push_back(i);
}
}
if(alice*2 <= sum)
printf("0\n");
else
{
printf("%d\n", ve.size());
int len = ve.size();
for(int i=0; i<len; i++)
{
printf("%d", ve[i] + 1);
printf("%c", i == len-1 ? '\n' : ' ');
}
}
}
return 0;
}
C. Tiles:http://codeforces.com/contest/1178/problem/C
C题不好描述,看图原题
分析:
首先看样例就感觉和2的n次幂有关,自然会王这方面想。然后看图只看一行时会发现相邻的两个图形,相对于对方都只能有两个状态(通过旋转),自然就是2*2*2*2.......这样的了,就是2^m;接着看多行当某一行固定后相邻的的两行相对于对方也有两种状态,就是2^n;所以最后的结果就是2^m * 2^n = 2^(n+m),用快速幂解决即可。
code:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL pow_mod(LL a, LL n, LL mod)
{
LL res = 1;
while(n)
{
if(n&1)
res = res * a % mod;
a = a * a % mod;
n /= 2;
}
return res;
}
int main()
{
LL n, m;
while(scanf("%lld %lld", &n, &m) != EOF)
{
printf("%lld\n", pow_mod(2, m+n, 998244353));
}
return 0;
}