当前位置:网站首页>Codeforces Round #579 (Div. 3) A 、B、E
Codeforces Round #579 (Div. 3) A 、B、E
2022-07-21 10:03:00 【冰冷灬泡面】
Codeforces Round #579 (Div. 3)
A-Circle of Students【暴力】
思路:
简单水题目,把数组多复制一串在后头,然后遇到1先向右搜索,然后向左搜索,解决了。
代码:
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--) {
int n;
int data[2000];
cin >> n;
for(int i = 0; i < n; i++) {
cin >> data[i];
}
//向后复制一串
for(int i = n; i < 2*n; i++) {
data[i] = data[i-n];
}
int count = 1;
int ans = 0;
int flag = 0;
//向右搜索
for(int i = 0; i < 2*n; i++) {
if(data[i] == 1) {
count = 1;
for(int j = i; j < 2*n; j++) {
if(count == data[j]) {
if(count == n) {
flag = 1;
break;
}
count++;
continue;
}
else
break;
}
if(flag == 1) {
break;
}
}
}
if(flag == 1) {
printf("YES\n");
continue;
}
//向左搜索
count = 1;
for(int i = 2*n-1; i >= 0; i--) {
if(data[i] == 1) {
count = 1;
for(int j = i; j >= 0; j--) {
if(count == data[j]) {
if(count == n) {
flag = 1;
break;
}
count++;
continue;
}
else
break;
}
if(flag == 1) {
break;
}
}
}
if(flag == 1)
printf("YES\n");
else if(flag == 0)
printf("NO\n");
}
return 0;
}
B-Equal Rectangles
思路:
由于因数的性质,只有让最小的和最大的匹配,第二小的和第二大的匹配才能构造出相等的面积。并且还要判断一下边数是否能匹配。
代码:
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
int a[4000];
for(int i = 0; i < 4*n; i++) {
cin >> a[i];
}
sort(a,a+4*n);
//由于因数的性质,一定是最小的和最大的,第二小和第二大的组合,以此类推
int p = 4*n-1;
int temp = a[0] * a[p];
int ans = 0;
for(int i = 0; i < 2*n; i+=2) {
if(a[i] * a[p] != temp) {
ans = 1;
break;
}
else
p -= 2;
}
//保证所有边都是成对出现的
for(int i = 0; i < 4*n; i+=2) {
if(a[i] != a[i+1]) {
ans = 1;
break;
}
}
if(ans == 1)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
E-Boxers【桶排+贪心】
思路:
桶排计算出每个体重的选手的数量,接着让每个选手都先尽可能的降低体重,然后保持体重,最后才增加体重。不过,要特判一下体重为 1 的选手,因为体重不能为 0。
代码:
#include<string.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define ll long long
ll a[200000];
ll tp[150005];
ll tp2[150005];
int main() {
ll n;
scanf("%lld",&n);
//这里是两个桶排,tp 记录的是不同体重选手的数量
//tp2 记录的是某个体重是否被加入队伍中。
memset(tp, 0, sizeof(tp));
memset(tp2, 0, sizeof(tp2));
for(int i = 0; i < n; i++) {
scanf("%lld",&a[i]);
tp[a[i]]++;
}
for(int i = 1; i < 150001; i++) {
if(i == 1) {
//这里特判体重为1的选手
if(tp[i] != 0) {
tp2[i]++;
tp[i]--;
}
if(tp[i] != 0) {
tp2[i+1]++;
tp[i]--;
}
}
else {
if(tp[i] != 0) {
//优先降低体重
if(tp2[i-1] == 0) {
tp2[i-1]++;
tp[i]--;
}
//然后保持体重
if(tp[i] != 0 && tp2[i] == 0) {
tp[i]--;
tp2[i]++;
}
//最后才是提升体重。
if(tp[i] != 0 && tp2[i+1] == 0) {
tp[i]--;
tp2[i+1]++;
}
}
}
}
ll ans = 0;
for(int i = 0; i < 150005; i++) {
if(tp2[i] != 0)
ans++;
}
cout << ans << endl;
return 0;
}
边栏推荐
- Interview Beijing XX technology summary
- H3C交換機查看相關的命令
- Chinese herbal medicine recognition based on deep neural network
- A year has passed, has livedata really been replaced by flow? Will livedata be discarded?
- Compass Sinan
- Un7.20: how to display two attributes in an association table at the same time?
- 6. < tag dynamic planning and housebreaking collection (tree DP) > lt.198 Home raiding + lt.213 Looting II + lt.337 Looting III DBC
- mysql.h: No such file or directory
- In the cloud native era, developers should have these five capabilities
- 显示一个圆,并可以移动
猜你喜欢
Ali Er Mian: what is MMAP? (not MMP)
VLAN and layer 3 switch
阿里二面:什么是mmap ?(不是mmp)
基于JSP实现OA办公系统
Quartz simple usage and its es job
Un7.20: how to display two attributes in an association table at the same time?
Static routing principle and configuration
这价格够香!灵耀14 2022影青釉秒杀:12代酷睿+2.8K OLED屏
What data problems will you encounter in the process of data governance?
Kuberntes cloud native combat high availability deployment architecture
随机推荐
一个非常简单的函数为什么会崩溃
SQL daily practice (Niuke new question bank) - day 3: condition query
Why can redis single thread be so fast
How airbnb realizes dynamic expansion of kubernetes cluster
Redis到底是单线程还是多线程
Resolved (selenium operation Firefox browser error) typeerror:__ init__ () got an unexpected keyword argument ‘firefox_ options‘
MySQL performance optimization (III): in depth understanding of indexing
Basic principle and configuration of switch
我,AI博士生,在线众筹研究主题
阿里云技术专家杨泽强:弹性计算云上可观测能力构建
ATL容器——CAtlMap,CRBMap
Codeforces Round #578 (Div. 2) A - Hotelier 【水题】
Un7.20: how to display two attributes in an association table at the same time?
身份证号码中间位数隐藏
SQL server数据库增量更新是根据 where 子句来识别的吗? 那做不到流更新吧? 每个表要
grafana可视化配置图表table
OpenMMLAB系列框架解读(基于PyTorch)
maya咖啡机建模
[214] PHP reads the writing method of all files in the directory
Why does a very simple function crash