Educational Codeforces Round 88 (Rated for Div. 2) 参赛人数19992
[codeforces 1359B] New Theatre Square 2块对应的数量统计
总目录详见https://blog.csdn.net/mrcrack/article/details/103564004
在线测评地址https://codeforces.com/contest/1359/problem/B
Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|
B - New Theatre Square | GNU C++17 | Accepted | 31 ms | 300 KB |
思路:
若x<=y/2,全部由x来实现
若x>y/2,2块的由y实现,1块的由x实现。
该题的难点在于2块数量的统计,详见代码。
AC代码如下
#include <stdio.h>
char map[105][1005];
int main(){
int t,n,m,x,y,i,j,cnt1,cnt2,ans;
scanf("%d",&t);
while(t--){
scanf("%d%d%d%d",&n,&m,&x,&y);
for(i=0;i<n;i++)scanf("%s",map[i]);
cnt1=cnt2=0;
for(i=0;i<n;i++){
j=0;
while(j<m){
if(map[i][j]=='.'&&map[i][j+1]=='.')cnt2++,j+=2;//2块数量统计
else if(map[i][j]=='.')cnt1++,j+=1;//1块数量统计
else j+=1;//此处别忘了,可能遇到'*'的情况
}
}
if(x<=y/2)ans=x*(cnt1+cnt2*2);//全用x来计费
else ans=x*cnt1+y*cnt2;//x,y分开计费
printf("%d\n",ans);
}
return 0;
}
类似题目