比赛地址
A.
思路:直接STL调用string类库函数就行
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string s;
cin>>s;
reverse(s.begin(),s.end());
for(int i=3;i<s.length();i+=3){
s.insert(i,",");
i++;
}
reverse(s.begin(),s.end());
cout<<s<<endl;
return 0;
}
B.
思路:只要行或者是列出现偶数,就肯定不可能出现中心位置,这是显而易见的,当行和列都是奇数,即中心位置能出现时,每次(n-1)/2,(m-1)/2,将行和列减半得到的是中心位置的坐标,每得到一次都需要将个数*4,由对称性可知,这也是很显然的
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll quick_pow(ll x,ll y)
{
ll ans=1;
while(y){
if(y&1)ans=ans*x;
x=x*x;
y>>=1;
}
return ans;
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll n,m;
cin>>n>>m;
ll sum=0,ans=1;
if(n%2==0||m%2==0){
sum=0;
}else{
while((n&1)&&(m&1)){
n=(n-1)/2,m=(m-1)/2;
sum+=ans;
ans*=4;
}
}
cout<<sum<<endl;
return 0;
}
C.
思路:优先队列
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
struct node{
int h,m,s;
friend bool operator < (node n1,node n2){
if(n1.h==n2.h){
if(n1.m==n2.m)return n1.s>n2.s;
return n1.m>n2.m;
}
return n1.h>n2.h;
}
};
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin>>n;
int a,b,c;
priority_queue<node> pq;
node nd;
for(int i=0;i<n;i++){
cin>>a>>b>>c;
nd.h=a,nd.m=b,nd.s=c;
pq.push(nd);
}
while(!pq.empty()){
nd=pq.top();pq.pop();
cout<<nd.h<<' '<<nd.m<<' '<<nd.s<<endl;
}
return 0;
}
D.
思路:DP+STL,参考重现赛大佬题解
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int N=1e5+10;
ll dp[N];
struct node{
ll id,pri;
};
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll n,k;
cin>>n>>k;
memset(dp,0,sizeof(dp));
node nd[N];
deque<node> pq;
ll sum=0;
for(int i=1;i<=n;i++){
cin>>nd[i].pri;
nd[i].id=i;
sum+=nd[i].pri;
}
for(int i=1,pos=0;i<=n;i++,pos++){
while(!pq.empty()&&dp[pos]<=pq.back().pri)pq.pop_back();
pq.push_back({pos,dp[pos]});
if(pos-pq.front().id>k)pq.pop_front();
dp[i]=pq.front().pri+nd[i].pri;
}
for(int i=n-k+1;i<=n;i++){
dp[i]=min(dp[i],dp[i-1]);
}
cout<<sum-dp[n]<<endl;
return 0;
}
E.
思路:数学推导,推出公式:Ai=A0+(An-A0)/n*i
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
int n,a0,an,q,l,r;
cin>>n>>a0>>an>>q;
//if(a0>an)swap(a0,an);
while(q--){
cin>>l>>r;
ll sum=0;
for(int i=l;i<=r;i++){
sum+=a0+(an-a0)/n*i;
}
cout<<sum<<endl;
}
return 0;
}
H.
思路:模拟
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--){
double a,b,c;
scanf("%lf%lf%lf",&a,&b,&c);
double ans=a*c/b;
double res=ans;
for(int k=1;k<=3;k++){
res*=10;
int n=(int)res%10;
if(k<3)continue;
if(n<=4)break;
else if(n>=6)break;
else if(n==5){
int m=(int)(res*1000000)%10;
if(m!=0)ans-=0.005,ans+=0.01;
else{
if(((int)(ans*100)%10)%2==1)ans-=0.005,ans+=0.01;
else ans-=0.005;
}
}
}
printf("%.2lf\n",ans);
}
return 0;
}
J.
思路:n<=9,直接枚举同分异构体数目就好
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int n;
cin>>n;
int ans;
if(n<4)ans=1;
else if(n==4)ans=2;
else if(n==5)ans=3;
else if(n==6)ans=5;
else if(n==7)ans=9;
else if(n==8)ans=18;
else if(n==9)ans=35;
cout<<ans<<endl;
return 0;
}