A:Maxim and Biology
因为数据范围比较小,就暴力就完事儿了。
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int convert(char a, char b)
{
if (a == b)
return 0;
if (a > b)
swap(a, b);
int x = b - a;
a = a - 'A' + 26;
b = b - 'A';
int y = a - b;
return x < y ? x : y;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n = 0, ans = INF;
string s;
cin >> n;
cin >> s;
for (int i = 0; i <= n - 4; i++)
{
int t = 0;
t += convert(s[i], 'A');
t += convert(s[i + 1], 'C');
t += convert(s[i + 2], 'T');
t += convert(s[i + 3], 'G');
if (t < ans) ans = t;
}
cout << ans << endl;
return 0;
}
B:Dima and a Bad XOR
因为要求异或最终结果大于零,那么由异或的性质可以得到,只要给定的数里有两个及以上不同的数,一定是满足题目要求的,否则的话,就全异或起来看一看就OK了。
#include <bits/stdc++.h>
using namespace std;
int x[520][520];
set<int>s;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
#endif // ONLINE_JUDGE
cin.tie(0);
cout.tie(0);
int n,m,id = -1;
cin >> n >> m;
for(int i = 1;i <= n; i++)
{
s.clear();
for(int j = 1;j <= m; j++)
{
cin >> x[i][j];
s.insert(x[i][j]);
}
if(s.size() >= 2)
id = i;
}
if(id == -1)
{
int ans = 0;
for(int i = 1;i <= n; i++)
ans ^= x[i][1];
if(ans)
{
cout << "TAK" << endl;
for(int i = 1;i <= n; i++)
cout << 1 << " ";
cout << endl;
}
else
cout << "NIE" << endl;
}
else
{
cout << "TAK" << endl;
int ans = 0,k;
for(int i = 1;i <= n; i++)
if(i != id)
ans ^= x[i][1];
for(int i = 1;i <= m; i++)
{
k = ans ^ x[id][i];
if(k)
{
for(int j = 1;j <= n; j++)
{
if(j != id)
cout << 1 << " ";
else
cout << i << " ";
}
cout << endl;
break;
}
}
}
return 0;
}
C:Problem for Nazar
一种前缀和的思想,既然是让求指定区间的和,那么就可以用大区间的和减去小区间的和。只不过因为数据的问题,很明显不能用一个数组存储前缀和。但是数列是有规律的,可以数出区间内有多少偶数,多少奇数,这些奇数偶数都是有规律的,就可以求和,然后计算就OK了。
#include<bits/stdc++.h>
typedef int in;
#define int long long
using namespace std;
const int mod = 1e9+7;
int xx[2];
int sum(int x)
{
int f = 0,c = 1;
xx[0] = 0;
xx[1] = 0;
while(x)
{
xx[f] += min(c,x);
x -= min(c,x);
f = !f;
c *= 2;
}
int ji = ((xx[0] % mod) * (xx[0] % mod)) % mod;
int ou = ((xx[1] % mod) * ((xx[1] + 1) % mod)) % mod;
return (ji + ou) % mod;
}
in main()
{
int l,r;
cin >> l >> r;
int ans = (sum(r) - sum(l-1) + mod) % mod;
cout << ans << endl;
return 0;
}
D:Stas and the Queue at the Buffet
性价比排序,找到最佳的性价比,排序完成后根据题目要求算和就OK了。
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 10;
typedef struct node
{
ll a,b;
bool operator < (const node &r)
{
ll x = a - b;
ll y = r.a - r.b;
return x > y;
}
};
node x[maxn];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
#endif // ONLINE_JUDGE
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
for(ll i = 0;i < n; i++)
cin >> x[i].a >> x[i].b;
sort(x,x + n);
ll ans = 0;
for(ll i = 0;i < n; i++)
ans += (x[i].a * i + x[i].b * (n - i - 1));
cout << ans << endl;
return 0;
}
标签:int,ll,cin,553,Codeforces,xx,tie,Div,mod From: https://blog.51cto.com/u_16131191/6356124