AtCoder Beginner Contest 088

A

模拟。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;
int main()
{
int n,a;
while(cin>>n>>a){
int s=n%500;
if(s<=a){
cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;
}
return 0;
}

B

猜一下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <algorithm>
using namespace std;
int a[101];

bool cmp(int x,int y)
{
return x>y;
}

int main()
{
int n;
while(cin>>n){
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n,cmp);
int sum1=0,sum2=0;
for(int i=0;i<n;i++){
if(i%2==0) sum1+=a[i];
else sum2+=a[i];
}
cout<<sum1-sum2<<endl;
}
return 0;
}

C

推式子。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// LUOGU_RID: 174585431
#include<iostream>
using namespace std;
int c[4][4];
int main()
{
for(int i=1;i<=3;i++)
for(int j=1;j<=3;j++)
cin>>c[i][j];
if
(
c[1][3]==c[3][3]-c[3][1]+c[1][1]&&
c[1][2]==c[2][2]-c[2][1]+c[1][1]&&
c[2][3]==c[3][3]-c[3][1]+c[2][1]&&
c[3][2]==c[3][1]-c[2][1]+c[2][2]
)
cout<<"Yes";
else cout<<"No";
return 0;
}

D

找最短路,其他无关的弄掉即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
#define MAX_N 55
using namespace std;
char mapp[MAX_N][MAX_N];
int n, m, cnt;
int dist[MAX_N][MAX_N];
struct node
{
int x, y;
} q[MAX_N * MAX_N];
bool pd[MAX_N][MAX_N];
const int r[] = {1, -1, 0, 0}, w[] = {0, 0, 1, -1};
inline void BFS(int sx, int sy)
{
int hd, tl, dx, dy, fx, fy;
hd = tl = 1;
q[1].x = sx;
q[1].y = sy;
while (hd <= tl)
{
fx = q[hd].x;
fy = q[hd].y;
hd++;
for (int i = 0; i < 4; ++i)
{
dx = fx + r[i];
dy = fy + w[i];
if (dx < 1 || dy < 1 || dx > n || dy > m || mapp[dx][dy] == '#' || pd[dx][dy] == 1)
continue;
pd[dx][dy] = 1;
tl++;
q[tl].x = dx;
q[tl].y = dy;
dist[dx][dy] = dist[fx][fy] + 1;
if (dx == n && dy == m)
return;
}
}
}
int main()
{
memset(dist, 127 / 3, sizeof dist);
cin >> n >> m;
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
cin >> mapp[i][j];
if (mapp[i][j] == '#')
cnt++;
}
}
dist[1][1] = 1;
pd[1][1] = 1;
BFS(1, 1);
int ans = n * m - cnt - dist[n][m];
if (ans < 0)
puts("-1");
else
cout << ans;
return 0;
}