CodeForces Round #553 Div2

A. Maxim and Biology

代码:

#include <bits/stdc++.h>
using namespace std; int N;
string s;
int minn = 0x3f3f3f3f; int main() {
scanf("%d", &N);
cin >> s;
for(int i = ; i <= N - ; i ++) {
int cnt = ;
for(int j = i; j < i + ; j ++) {
if(j == i) {
if(s[j] == 'Z') cnt += ;
else cnt += min(s[j] - 'A', ('Z' - s[j] + ));
}
if(j == i + ) cnt += min(abs(s[j] - 'C'), ('Z' - s[j] + ));
if(j == i + ) cnt += min(abs(s[j] - 'T'), (s[j] - 'A' + ));
if(j == i + ) cnt += min(abs(s[j] - 'G'), ('Z' - s[j] + ));
}
minn = min(minn, cnt);
}
printf("%d\n", minn);
return ;
} /*
9
AAABBBCCC
*/

C. Problem for Nazar

代码:

#include <bits/stdc++.h>
using namespace std; const int mod = 1e9 + ;
long long l, r; long long sum(long long x) {
if(x <= ) return ;
int flag = ;
long long t = ;
long long sum1 = , sum2 = ;
for(long long i = ; i < x; ) {
long long nx = min(i + t, x);
if(flag) sum1 += (nx - i);
else sum2 += (nx - i); t *= ;
i = nx;
flag ^= ;
}
long long ans = sum2 % mod * ((sum2 + ) % mod) % mod + sum1 % mod * (sum1 % mod) % mod;
return ans % mod;
} int main() {
cin >> l >> r;
cout << (sum(r) - sum(l - ) + mod) % mod << endl; return ;
}

D. Stas and the Queue at the Buffet

代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + ;
int N; struct Node {
long long a;
long long b;
}node[maxn]; bool cmp(const Node &n, const Node &m) {
return (n.a - n.b) > (m.a - m.b);
} int main() {
scanf("%d", &N);
for(int i = ; i <= N; i ++)
cin >> node[i].a >> node[i].b; sort(node + , node + + N, cmp);
long long ans = ;
for(int i = ; i <= N; i ++)
ans += (node[i].a * (i - ) + node[i].b * (N - i)); cout << ans << endl; return ;
}

E. Number of Components

代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + ;
int N;
long long a[maxn]; int main() {
scanf("%d", &N);
for(int i = ; i <= N; i ++)
cin >> a[i]; long long ans = ;
for(int i = ; i <= N; i ++) {
if(a[i] > a[i - ])
ans += (a[i] - a[i - ]) * (N - a[i] + );
else if(a[i] != a[i - ])
ans += (a[i - ] - a[i]) * a[i];
} cout << ans << endl; return ;
}
上一篇:无法安装Java,以下开关中存在错误:“0”


下一篇:ligerui_实际项目_003:form中添加数据,表格(grid)里面显示,最后将表格(grid)里的数据提交到servlet