A题:https://codeforces.com/contest/1096/problem/A
题解:
(输出2*l即可)
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
const int N=3e5+7;
const long long mod=1e9+7;
int main(){
int t;
int l,r;
scanf("%d",&t);
while(t--){
scanf("%d%d",&l,&r);
printf("%d %d\n",l,2*l);
}
return 0;
}
B题:https://codeforces.com/contest/1096/problem/B
题解:
按题意可以分3种情况。
ab aba abc
ab 与abc这两种情况只要将a的个数和b的个数+1.
aba的情况则只要将(第一个a的个数+1)*(最后一个a的个数+1)
最后按照题目取模即可。
C题:https://codeforces.com/contest/1096/problem/C
题解:
可以将题目给出的图看成一个圆,然后枚举每个n边形所对应的最小角或者此次小角(若最小角不是整数而此小角是)
之后枚举这些情况即可(注意每次判定都要对当前的值看是否超出最大角,若超出则是错的)
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
const int N=3e5+7;
const long long mod=1e9+7;
int que[N],wei[N],maxn[N];
int main(){
int n;
int t;
int tot=0;
for(int i=3;i<=10000;i++){
if(((i-2)*180)%i!=0){
continue;
}
if((180-(((i-2)*180)/i))%2==1) que[++tot]=(180-(((i-2)*180)/i));
else que[++tot]=(180-(((i-2)*180)/i))/2;
wei[tot]=i;
maxn[tot]=((i-2)*180)/i;
//cout<<que[tot]<<endl;
}
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=1;i<=tot;i++){
if(n>maxn[i]) continue;
if(n%que[i]==0){
printf("%d\n",wei[i]);
break;
}
}
}
return 0;
}
D题:https://codeforces.com/contest/1096/problem/D
题解:
记录4中状态:
前i段不存在h 记作0
前i段不存在ha 记作1
前i段不存在har 记作2
前i段不存在hard 记作3
于是记dp[i][j]
第一维代表状态
第二维代表位置
为了确保前i段无h 则当i出现h时需要花费代价删去该位置的h
于是得到 dp[0][i]=dp[0][i]+a[i]*(str[i]=='h')
为了确保前i段无ha 需考虑2种情况:
1.对于前i-1段无h,不管第i段是什么值 都满足条件
2.对于前i-1段无ha,当第i个位置出现a时花费代价删掉该位置的a即可
于是对于前i段无ha的最小代价则是dp[1][i]=min(dp[0][i-1],dp[1][i-1]+a[i]*(str[i]=='a'))
之后2种状态同理(注意 对于后2中只要考虑上一种状态即可,因为前i段无h的最下代价肯定大于等于前i段无ha的最小代价)
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
const int N=3e5+7;
const long long mod=1e9+7;
char str[N];
ll dp[6][N];
ll a[N];
ll Min(ll x,ll y){
if(x<y) return x;
return y;
}
int main(){
int n;
scanf("%d",&n);
scanf("%s",str+1);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
for(int i=1;i<=n;i++){
dp[0][i]=dp[0][i-1]+(str[i]=='h')*a[i];
dp[1][i]=Min(dp[1][i-1]+a[i]*(str[i]=='a'),dp[0][i-1]);
dp[2][i]=Min(dp[2][i-1]+a[i]*(str[i]=='r'),dp[1][i-1]);
dp[3][i]=Min(dp[3][i-1]+a[i]*(str[i]=='d'),dp[2][i-1]);
}
printf("%lld\n",Min(Min(dp[0][n],dp[1][n]),Min(dp[2][n],dp[3][n])));
return 0;
}