当前位置:网站首页>Codeforces Round #810 (Div.2) A-C
Codeforces Round #810 (Div.2) A-C
2022-07-27 06:39:00 【Hama_ecco】
Codeforces Round #810 (Div.2) A-C
A. Perfect Permutation
题意及要求: 给定一个整数
n,构成一个从1到n无重复排列中,a[i]能被i整除的个数最少。思路: 当
n大于1时,n-1不可能被n整除。 所以 首先输出n,再输出1到n-1。
代码:
#include<bits/stdc++.h>
#define IOS std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define int long long
#define endl "\n"
using namespace std;
const int mn = 1e5+10;
const int mod = 1e9+7;
const int N = 2e5+10;
int dr[4][2]={
{-1,0},{1,0},{0,-1},{0,1}};
void solve(){
int n;
cin >>n;
cout <<n<<" ";
for(int i=1;i<n;i++){
cout <<i<<" ";
}
cout <<endl;
}
signed main(){
IOS;
int T=1;
cin >>T;
while(T--){
solve();
}
return 0;
}
B. Party
题意及要求: 一共
m对朋友,共n个人,每个人都有一个不开心值a[i],如果他没有被邀请,则总不开心值就增加a[i],现举行派对,每对朋友可以分享一个蛋糕,但要求 最后吃掉的蛋糕数量为偶数 。思路:若
m为偶数,则将所有人邀请时,蛋糕数量一定为偶数若
m为奇数,则邀请所有人时蛋糕数量为奇数,则将蛋糕数量变为偶数:
- 删去一个人
j,且这个人的朋友为num[j]且必须是奇数,相当于少了奇数 (num[j]) 个蛋糕;- 删去一对朋友
j1,j2,且这两个人的朋友数量 (num[j1]与num[j2]) 均为偶数,则蛋糕相当于少了奇数 (1+num[j1]+num[j2]) 个。
代码:
#include<bits/stdc++.h>
#define IOS std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define int long long
#define endl "\n"
//#pragma GCC optimize(2)
using namespace std;
const int mn = 1e5+10;
const int mod = 1e9+7;
const int N = 2e5+10;
int dr[4][2]={
{-1,0},{1,0},{0,-1},{0,1}};
int a[N];//记录每个人的不开心值
int num[N];//每个人出现的次数
int people[N][2];//记录每对朋友
void solve(){
memset(num,0,sizeof num);
int n,m;
cin >>n>>m;
for(int i=1;i<=n;i++){
cin >>a[i];
}
for(int i=1;i<=m;i++){
cin >>people[i][0]>>people[i][1];
num[people[i][0]]++;
num[people[i][1]]++;
}
if(m%2==0){//若m是偶数,则邀请所有人去派对吃的蛋糕一定是偶数
cout <<0<<endl;
return;
}
int ans = 0x3f3f3f3f;
for(int i=1;i<=m;i++){//去掉一对朋友,且他们朋友数均为偶数
if(num[people[i][0]]%2==0&&num[people[i][1]]%2==0){
ans=min(ans,a[people[i][0]]+a[people[i][1]]);
}
}
for(int i=1;i<=n;i++){//去掉一个人,且他的朋友是奇数
if(num[i]&1){
ans=min(ans,a[i]);
}
}
cout <<ans<<endl;
}
signed main(){
IOS;
int T=1;
cin >>T;
while(T--){
solve();
}
return 0;
}
C. Color the Picture
题意及要求: 给定
n*m的矩阵,现有k种颜料,每种颜料可以使用a[i]次。问有没有一种染色方法,可以让矩阵中的每个格子,它的周围四个格子至少有三个格子和它的颜色相同。
思路: 可以自己画图试一下,最终发现同一种颜色颜料,只能染至少两行或两列。所以直接暴力按行染色和按列染色即可。
代码:
#include<bits/stdc++.h>
#define IOS std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define int long long
#define endl "\n"
using namespace std;
const int mn = 1e5+10;
const int mod = 1e9+7;
const int N = 2e5+10;
int dr[4][2]={
{-1,0},{1,0},{0,-1},{0,1}};
int a[mn];
int b[mn];
int c[mn];
void solve(){
int n,m,k;
cin >>n>>m>>k;
int t_a = min(n,m);
int t_b = max(n,m);
int line_a=t_b;
int line_b=t_a;
for(int i=1;i<=k;i++){
cin >>c[i];
a[i]=c[i];//每种染料能染几行
b[i]=c[i];//每种染料能染几列
a[i]/=t_a;
b[i]/=t_b;
}
sort(a+1,a+1+k);
sort(b+1,b+1+k);
for(int i=1;i<=k;i++){
if( c[i]>=(n*m) ){
cout<<"YES"<<endl;
return;
}
if(a[i]>=line_a||b[i]>=line_b){
cout<<"YES"<<endl;
return;
}
if(a[i]>1){
if(line_a-a[i]!=1){
line_a-=a[i];
}else{
if(a[i]!=2)
line_a-=(a[i]-1);
}
}
if(b[i]>1){
if(line_b-b[i]!=1){
line_b-=b[i];
}else{
if(b[i]-1!=1)
line_b-=(b[i]-1);
}
}
if(line_a<=0||line_b<=0){
cout <<"YES"<<endl;
return;
}
}
cout <<"NO"<<endl;
}
signed main(){
IOS;
int T=1;
cin >>T;
while(T--){
solve();
}
return 0;
}
边栏推荐
- Pg_relation_size 问题
- Shell系统学习之Shell条件测试,判断语句和运算符
- No.0 training platform course-2. SSRF Foundation
- Gossip: talk with your daughter about why you should learn culture lessons well
- Chapter 6 Shell Logic and Arithmetic
- Quickly update the information in a field in kettle
- ? Experiment 7 implementation of PHP management system based on MySQL
- Calledprocesserror during pre commit install
- Convert Excel to csv/csv UTF-8
- Excuse me, MySQL timestamp (6) using flick SQL is null. Is there a way to deal with this
猜你喜欢

Cadence(十一)丝印调整和后续事项

Tcp/ip protocol analysis (tcp/ip three handshakes & four waves + OSI & TCP / IP model)

在kettle使用循环来处理表中的数据
![[wsl2] configure the USB camera connecting the USB device and using the host](/img/03/7ebc7eebeda1598c8f4fdd1e9188c7.png)
[wsl2] configure the USB camera connecting the USB device and using the host

35. Search Insert Position 搜索插入位置

【WSL2】配置连接 USB 设备并使用主机的 USB 摄像头

Quartus: an error is reported when adding a.V file to someone else's project

杂谈:最近好多朋友谈出国……

C语言程序设计 | 程序编译与预处理

C# Winfrom 常用功能整合-2
随机推荐
Tcp/ip protocol analysis (tcp/ip three handshakes & four waves + OSI & TCP / IP model)
35. Search insert position
在Perl程序中暴露Prometheus指标
? Experiment 7 implementation of PHP management system based on MySQL
JS make a traffic light
Logcat tool
在kettle使用循环来处理表中的数据
Instruction set x digital technology accelerates the digital transformation of government and enterprises, and builds Unicorn enterprise alliance in DT field
Flutter实战-请求封装(一)
网络入门——vlan及trunk概述
?实验 7 基于 Mysql 的 PHP 管理系统实现
ClickHouse 笔记1 | 简介、特点 | 基于CentOS7系统的安装与使用 | 常用数据类型 | MergeTree 表引擎 | SQL操作
Single arm routing (explanation + experiment)
零号培训平台课程-2、SSRF基础
Bash: 创建返回布尔类型值的函数
Gossip: Recently, many friends talk about going abroad
Binary tree -- natural search semantics (1) Basics
js做一个红绿灯
The possibility of metauniverse from the perspective of technical principles: how Omniverse "built" Mars
Pytorch notes: td3
