0%

AcWing2022春季每日一题-2-第四周

AcWing2022春季每日一题,第二周题解

AcWing 1812. 方形牧场—原题链接

题目标签:枚举

思路:
暴力枚举即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;

int main()
{
int x1, y1, x2, y2;
x1 = y1 = 15, x2 = y2 = 0;
int a1, b1, c1, d1, a2, b2, c2, d2;
cin >> a1 >> b1 >> c1 >> d1 >> a2 >> b2 >> c2 >> d2;
x1 = min(x1, min(a1, min(c1, min(a2, c2))));
y1 = min(y1, min(b1, min(d1, min(b2, d2))));
x2 = max(x2, max(a1, max(c1, max(a2, c2))));
y2 = max(y1, max(b1, max(d1, max(b2, d2))));

int n = max(abs(x2 - x1), abs(y2 - y1));
cout << n * n << endl;
return 0;
}

AcWing 1800. 不做最后一个!—原题链接

题目标签:

思路:
n不大于100,因此直接暴力,非常滴暴力且不聪明

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
#include <bits/stdc++.h>
using namespace std;daaaaaaa
typedef long long LL;
typedef pair<int, int> PII;
int n;

void solve();

int main()
{
cin >> n;
unordered_map<string, int> mp = {{"Bessie", 0},{"Elsie", 0},{"Daisy", 0},{"Gertie", 0},{"Annabelle", 0},{"Maggie", 0},{"Henrietta", 0}};
while(n--)
{
string s;
int x;
cin >> s >> x;
mp[s] += x;
}

vector<pair<string, int>> v1;
int minn = 0x3f3f3f3f;
for(auto t : mp)
{
minn = min(minn, t.second);
}
for(auto t : mp)
{
if(t.second != minn) v1.push_back(t);
}
if(v1.size() == 0)
{
puts("Tie");
return 0;
}
vector<pair<string, int>> v2;
minn = 0x3f3f3f3f;
for(int i=0; i<v1.size(); i++)
{
minn = min(minn, v1[i].second);
}
for(int i=0; i<v1.size(); i++)
{
auto t = v1[i];
if(t.second == minn) v2.push_back(t);
}
if(v2.size() == 1) cout << v2[0].first << endl;
else puts("Tie");
// system("pause");
return 0;
}

AcWing 1788. 牛为什么过马路—原题链接

题目标签:模拟

思路:
直接模拟

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
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const int N = 11;
const int INF = 0x3f3f3f3f;
int n, cnt;
int p[N];

void solve();

int main()
{
memset(p, -1, sizeof p);
cin >> n;
while(n--)
{
int a, b;
cin >> a >> b;
if(p[a] == -1)
{
p[a] = b;
continue;
}
if(p[a] != b)
{
p[a] = b;
cnt++;
}
}
cout << cnt << endl;
// system("pause");
return 0;
}

AcWing 1775. 丢失的牛—原题链接

题目标签:模拟

思路:直接模拟就行

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
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

int x, y;
int cnt;
int dist, now, last;

void solve();

int main()
{
cin >> x >> y;

int dist = 0, step = 1, last = x;
while(true)
{
int next = x + step;
if((y >= last && y <= next) || (y >= next && y <= last))
{
dist += abs(last - y);
break;
}
dist += abs(last - next);
step *= (-2);
last = next;
}
cout << dist << endl;
// system("pause");
return 0;
}

AcWing 1866. 围栏刷漆—原题链接

题目标签:集合

思路:
虽然可以暴力模拟,但是集合才应该是本题的考点,两个线段集合在确定头部关系的情况下只有包含,重合,不重合三种情况,分类讨论即可

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
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

int a, b, c, d;

void solve();

int main()
{
cin >> a >> b >> c >> d;
if(a > c)
{
swap(a, c);
swap(b, d);
}
if(c > d)
{
cout << b + d - a - c << endl;
}
else if(d < b)
{
cout << b - a << endl;
}
else
{
cout << d - a << endl;
}
// system("pause");
return 0;
}

AcWing 1854. 晋升计数—原题链接

题目标签:模拟

思路:
模拟 × 阅读理解 √, 并且使用n是为了兼容比赛组别不一定为4的情况

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 <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int n;
int a[N], b[N], res[N];

void solve();

int main()
{
n = 4;
for(int i=1; i<=n; i++) cin >> a[i] >> b[i];

res[n] = b[n] - a[n];
for(int i=n-1; i>=2; i--)
{
res[i] = res[i+1] + b[i] - a[i];
}
for(int i=2; i<=n; i++) cout << res[i] << endl;
return 0;
// system("pause");
return 0;
}