当前位置:网站首页>【AtCoder Beginner Contest 261 (A·B·C·D)】
【AtCoder Beginner Contest 261 (A·B·C·D)】
2022-07-27 00:28:00 【Romantic dog】
Better reading experience \color{red}{ Better reading experience } Better reading experience
Catalog
A - Intersection
The main idea of the topic
Given the endpoints of two colored intervals L 1 , R 1 , L 2 , R 2 L_1,R_1,L_2,R_2 L1,R1,L2,R2, Find the length of the interval dyed with two colors at the same time
thought
- Data range is small , Violence enumeration interval
- Traverse two intervals , use
res[i]Record the staining - Traverse the dyed interval , Calculate the interval length
Code
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int res[N];
int main(){
int a, b, c, d;
cin >> a >> b >> c >> d;
for(int i = a; i <= b; i ++) res[i]++;
for(int i = c; i <= d; i ++) res[i]++;
int cnt = 0;
for(int i = 0; i <= 200; i ++) if(res[i] == 2) cnt++;
if(cnt) cout << cnt - 1 << endl;
else cout << 0 << endl;
return 0;
}
B - Tournament Result
The main idea of the topic
Given N × N N\times N N×N Table of , unit A i , j A_{i,j} Ai,j Recorded + i i i And j j j Three situations of winning or losing and drawing in the match , If there are conflicts in the records, it means that the table is incorrect
thought
- Traversal table , Traverse i i i That's ok , Each line from j = i + 1 j = i + 1 j=i+1 Column start
- Judge A i , j A_{i,j} Ai,j and A j , i A_{j,i} Aj,i Is your record consistent with the facts
- Mark the inconformity and exit
Code
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
char mp[N][N];
int n;
int main(){
cin >> n;
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= n; j++) cin >> mp[i][j];
}
bool flag = 1;
for(int i = 1; i <= n; i ++){
for(int j = i + 1; j <= n; j ++){
if(mp[i][j] == 'D' && mp[j][i] != 'D'){
flag = 0;
break;
}
else if(mp[i][j] == 'W' && mp[j][i] != 'L'){
flag = 0;
break;
}
else if(mp[i][j] == 'L' && mp[j][i] != 'W'){
flag = 0;
break;
}
}
if(!flag) break;
}
if(flag) cout << "correct" << endl;
else cout << "incorrect" << endl;
return 0;
}
C - NewFolder(1)
The main idea of the topic
Given N N N individual string Type of S S S strand , According to the given S S S The order of , For a total of m m m Time S i S_i Si, If the current S i S_i Si First appearance , Output S i S_i Si, Otherwise output S i ( u − 1 ) S_i(u-1) Si(u−1), u u u Indicates the number of occurrences
thought
string s[N]Store read in S S S The order ofmap<string,int> a,Record the current S i S_i Si How many times has it appeared- Traverse
s[N], bringa[s[i]]++, ifa[s[i]] - 1 == 0This is the first time
Code
#include <bits/stdc++.h>
using namespace std;
map<string,int> a;
int n;
const int N = 1e6 + 3;
string s[N];
int main(){
cin >> n;
for(int i = 0; i < n; i ++) cin >> s[i];
for(int i = 0; i < n; i ++){
a[s[i]]++;
int t = a[s[i]] - 1;
if(t != 0){
cout << s[i] << '(' << t << ')' << endl;
}
else cout << s[i] << endl;
}
return 0;
}
D - Flipping and Bonus
The main idea of the topic
Flip a coin to the front , The counter increases , On the contrary, the counter is cleared , Given N N N Coin toss is the money you get from the front X i X_i Xi, Given M M M Reward rules , If the value of the counter reaches C i C_i Ci, Will get Y i Y_i Yi Reward , Ask how to get the most money
thought
a[N]Record X i X_i Xi,b[N]Record Y i Y_i Yi- State means :
dp[i][j]Before presentationiSecond throw , The current counter value isjWhen you get money - State calculation :
- If the throw result is positive : be
dp[i][j] = dp[i - 1][j - 1] + a[i] + b[j] - On the contrary, the counter is cleared , Updated results :
dp[i][0] = max(dp[i][0],dp[i - 1][j])
- If the throw result is positive : be
- Pay attention
long long
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,m;
const LL N = 5010;
LL dp[N][N];
LL a[N];
LL b[N];
int main(){
cin >> n >> m;
for(int i = 1; i <= n; i ++) cin >> a[i];
for(int i = 0; i < m; i ++){
int x, y;
cin >> x >> y;
b[x] = y;
}
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= i; j ++){
dp[i][j] = dp[i - 1][j - 1] + a[i] + b[j];
}
for(int j = 0; j < i; j ++){
dp[i][0] = max(dp[i][0],dp[i - 1][j]);
}
}
LL ans = 0;
for(int i = 0; i <= n; i ++) ans = max(ans,dp[n][i]);
cout << ans << endl;
return 0;
}
边栏推荐
- Configure deeplobcut2 with your head covered
- Leetcode - linked list
- 哨兵2号(Sentinel-2)的下载及处理
- 【AtCoder Beginner Contest 261 (A·B·C·D)】
- LeetCode题目——二叉树篇
- LeetCode题目——数组篇
- PTA 7-3 lists leaf nodes
- 12_ Decision tree
- Shang school software testing (1) software testing curriculum system, advantages, learning suggestions, understanding software, software testing and defects, software testing process, debugging and te
- AutoCAD的卸载后重新安装,删除注册表的详细过程
猜你喜欢

Shang school software testing (1) software testing curriculum system, advantages, learning suggestions, understanding software, software testing and defects, software testing process, debugging and te

信号与系统学习零输入响应

Web middleware log analysis script 2.0 (shell script)

C语言 关机小程序

Anaconda => PyCharm => CUDA => cudnn => PyTorch 环境配置

知识蒸馏——pytorch实现

转置卷积相关

Drawing warehouse Tsai

Database: MySQL foundation +crud basic operation

裁剪tif影像
随机推荐
MySQL optimization
PTA 7-3 lists leaf nodes
[PCB open source sharing] stc8a8k64d4 development board
The crawler parses the object of the web page. Element name method
哨兵2号(Sentinel-2)的下载及处理
[PCB open source sharing] stc32g12k128/stc8h8k64u development board
2022-07-17:1, 2, 3... N-1, N, n+1, n+2... In this sequence, only one number has repetition (n). This sequence is unordered. Find the repeated number n. This sequence is ordered. Find the repeated numb
Signal and system learning zero input response
我的第一篇博客-迷茫的大三人
ResNet论文解读及代码实现(pytorch)
Xshell连接服务器时报“Could not load host key”错误
Recbole use 1
Error generating yolov5.wts file
输入一串字母 将里面的元音输出希望各位大佬能给指导
【AcWing第61场周赛】
2020-12-22最大公因数
Course notes of Professor Dalin of robotics platform
UNET notes
Arcgis和Cass实现断面展高程点
deeplabcut使用1