AtCoder Beginner Contest 176
A
code:
#include<iostream>
#include<cmath>
using namespace std;
int n,x, t;
int main()
{
cin>>n>>x>>t;
double a=n*1.0/x;
int ans=ceil(a);
ans=ans*t;
cout<<ans<<endl;
return 0;
}
B
#include<iostream>
#include<cmath>
using namespace std;
int n,x, t;
int main()
{
string s;
cin>>s;
int num =s.size();
int ans=0;
for(int i=0;i<num;i++){
ans+=s[i]-'0';
}
if(ans%9==0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
C
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int a[N];
int n,x, t;
int main()
{
cin>>n;
int maxx=0;
ll ans=0;
for(int i=1;i<=n;i++){
cin>>a[i];
if(maxx>a[i]){
ans+=maxx-a[i];
}
else maxx=a[i];
}
cout<<ans<<endl;
return 0;
}
D:
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
char G[N][N];
int to[4][2]={1,0,0,1,-1,0,0,-1};
int n,m;
int sx,sy,ex,ey;
bool vis[N][N];
int ans;
struct node{
int x;
int y;
};
bool check(int x,int y){
if(x>=1&&x<=n&&y>=1&&y<=m&&!vis[x][y]&&G[x][y]=='.') return true;
return false;
}
int bfs(node now){
int res=-1;
queue<node> q1,q2;
q1.push(now);
vis[now.x][now.y]=1;
node nxt;
while(q1.size()){
res++;
while(q1.size()){
now=q1.front();
q1.pop();
q2.push(now);//注意一定要把队列q1里面的数全都给q2,因为这里面的数都是有可能使用魔法的
if(now.x==ex&&now.y==ey){
return res;
}
for(int i=0;i<4;i++){
int dx=now.x+to[i][0];
int dy=now.y+to[i][1];
nxt={dx,dy};
if(check(dx,dy)){
q1.push(nxt);
vis[dx][dy]=1;
}
}
}
while(q2.size()){
now=q2.front();
q2.pop();
for(int i=-2;i<=2;i++)
for(int j=-2;j<=2;j++){
int dx=now.x+i;
int dy=now.y+j;
nxt={dx,dy};
if(check(dx,dy)){
q1.push(nxt);
vis[dx][dy]=1;
}
}
}
}
return -1;
}
int main()
{
scanf("%d%d",&n,&m);
scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
for(int i=1;i<=n;i++){
scanf("%s",G[i]+1);
}
node now={sx,sy};
ans=bfs(now);
printf("%d\n",ans);
return 0;
}