这次只用了一个电脑,比赛环境也是模拟的。
A
#include<bits/stdc++.h>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
bool pro[20];
int pen[20];
int cal(string t){
int hour = (t[0]-'0') * 10 + t[1]-'0';
int min = (t[3]-'0') * 10 + t[4]-'0';
return hour * 60 + min;
}
int main()
{
int T;
scanf("%d", &T);
while(T--){
int n, m;
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++){
pro[i] = false;
pen[i] = 0;
}
int num = 0, ans = 0;
while(m--){
int id;
string time, result;
scanf("%d", &id);
cin>>time>>result;
if(result == "AC" && pro[id-1000] == false && cal(time) <= 300){
ans += pen[id-1000] + cal(time);
pro[id-1000] = true;
num++;
}
else if(result == "PE" || result == "WA" || result == "RE" ||
result == "TLE" || result == "MLE" || result == "OLE"){
pen[id-1000] += 20;
}
}
printf("%d %d\n", num, ans);
}
}
B
#include<bits/stdc++.h>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 3000+20;
struct point{
int index;
ll cost;
point(){
index = cost = 0;
}
point(int i, ll c){
index = i;
cost = c;
}
};
point h[maxn];
bool cmp(point a, point b){
if(a.index < b.index)
return true;
return false;
}
ll dp[maxn][2];//0表示不建立
ll dist[maxn][maxn];//预处理数组 i-j的cost
int main()
{
int n;
while(scanf("%d", &n) != EOF){
for(int i = 1; i <= n; i++){
ll index, cost;
scanf("%d%lld", &index, &cost);
h[i] = point(index, cost);
}
sort(h + 1, h + n + 1, cmp);
dist[1][1] = 0;
for(int i = 1; i <= n; i++){
dist[i][i] = 0;
for(int j = i+1; j <= n; j++){
dist[i][j] = dist[i][j-1] + h[j].index - h[i].index;
}
}
dp[1][1] = h[1].cost;
dp[1][0] = 0x3f3f3f3f;
for(int i = 2; i <= n; i++){
dp[i][1] = min(dp[i-1][0], dp[i-1][1]) + h[i].cost;
dp[i][0] = 0x3f3f3f3f;
for(int j = 1; j <= i-1; j++){ //j建立
dp[i][0] = min(dp[i][0], dp[j][1] + dist[j][i]);
}
}
printf("%lld\n", min(dp[n][0], dp[n][1]));
}
}
C
#include<bits/stdc++.h>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e5 + 20;
int g1[maxn], g2[maxn];
int a[maxn];
int gcd(int a, int b){
return b == 0 ? a : gcd(b, a % b);
}
int main()
{
int T;
scanf("%d", &T);
while(T--){
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++){
scanf("%d", &a[i]);
}
//正序
g1[1]=a[1];
for(int i = 2; i <= n; i++){
g1[i] = gcd(g1[i-1], a[i]);
}
//逆序
g2[n]=a[n];
for(int i = n-1; i >= 1; i--){
g2[i] = gcd(g2[i+1], a[i]);
}
//遍历
int ans = 0;
ans = max(g2[2], g1[n-1]);
for(int i = 2; i <= n-1; i++){
ans = max(ans, gcd(g1[i-1], g2[i+1]));
}
printf("%d\n", ans);
}
}
E
#include<bits/stdc++.h>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MOD = 1e9+7;
ll qpow(ll a, ll b){
ll res = 1;
while(b){
if(b & 1)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
int main()
{
int T;
scanf("%d", &T);
while(T--){
int n, k;
scanf("%d%d", &n,&k);
ll ans = 0;
for(int i = 1; i <= n; i++){
ans = (ans + qpow(i,k)) % MOD;
}
printf("%lld\n", ans);
}
}
G
#include<bits/stdc++.h>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e5+20;
int a[maxn];
int main()
{
int T;
scanf("%d", &T);
while(T--){
int n;
scanf("%d", &n);
for(int i = 2; i <= n; i++)
scanf("%d", &a[i]);
bool flag = true;
int num = 0;
for(int i = n; i >= 2; i--){
if(a[i] == 1)
num++;
else
num--;
if(num < 0){
flag = false;
break;
}
}
num--;
if(num < 0)
flag = false;
if(num % 2 == 1)
flag = false;
if(!flag)
printf("No\n");
else
printf("Yes\n");
}
}