当前位置:网站首页>【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;
}
边栏推荐
- 20220720 toss deeplobcut2
- Knowledge distillation -- pytorch implementation
- Today's 20220719 toss deeplobcut
- 蒙着头配置deeplabcut 1
- yolov5在jetson nano上的部署 deepstream
- LeetCode——哈希表篇
- "Syntaxerror: future feature annotations is not defined"
- 【 Educational Codeforces Round 132 (Rated for Div. 2) A·B·C】
- [Qt]容器类、迭代器、foreach关键字
- Leetcode topic - binary tree chapter
猜你喜欢

The crawler parses the object of the web page. Element name method

uni-app学习(二)

Visual studio C cs0006 C failed to find metadata file

Complete review of parsing web pages

View where Anaconda created the environment

Midge paper reading notes

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

deeplabcut使用1

SSRF (server side request forgery) -- Principle & bypass & Defense

知识蒸馏——pytorch实现
随机推荐
寻找真凶
"Syntaxerror: future feature annotations is not defined"
解析网页的完整回顾
Midge paper reading notes
深度学习调参技巧
Uni app learning (II)
输入一串字母 将里面的元音输出希望各位大佬能给指导
JS, one of the methods of object merging Assign (), recursive assignment & method of array merging..., array. Concat (), array. Push. Apply (), array. Push ()
LeetCode——哈希表篇
Friend友元函数以及单例模式
C and pointer Chapter 18 runtime environment 18.7 problems
爬虫解析网页的 对象.元素名方法
8_多项式回归及模型泛化(Polynomial Regression and Model Generalization)
Drawing warehouse-2 (function image)
[LeetCode] 无重复最长字符串
Nacos installation and pit stepping
放图仓库-2(函数图像)
AutoCAD的卸载后重新安装,删除注册表的详细过程
C and pointer Chapter 18 runtime environment 18.2 interface between C and assembly language
Draw impact function