当前位置:网站首页>Codeforces Round #810 (Div.2) A-C
Codeforces Round #810 (Div.2) A-C
2022-07-27 07:32:00 【Hama_ ecco】
Codeforces Round #810 (Div.2) A-C
A. Perfect Permutation
Meaning and requirements : Given an integer
n, Form a slave1TonNo repeated arrangement ,a[i]Can beiThe number of divisions is the least .Ideas : When
nGreater than1when ,n-1It's impossible to bento be divisible by . therefore The first outputn, Then the output1Ton-1.
Code :
#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
Meaning and requirements : altogether
mTo friends , commonnpersonal , Everyone has an unhappy valuea[i], If he is not invited , Then the total unhappiness value increasesa[i], Now hold a party , Each pair of friends can share a cake , But ask for The number of cakes eaten at last is even .Ideas : if
mFor the even , When you invite everyone , The number of cakes must be evenif
mIt's odd , The number of cakes is odd when everyone is invited , Change the number of cakes to an even number :
- Delete a person
j, And this person's friend isnum[j]And must be odd , It is equivalent to missing odd numbers (num[j]) A cake ;- Delete a pair of friends
j1,j2, And the number of friends of these two people (num[j1]Andnum[j2]) They are all even numbers , Then the cake is equivalent to missing an odd number (1+num[j1]+num[j2]) individual .
Code :
#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];// Record everyone's unhappiness
int num[N];// The number of times each person appears
int people[N][2];// Record every pair of friends
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){// if m It's even , Then invite everyone to the party and eat an even number of cakes
cout <<0<<endl;
return;
}
int ans = 0x3f3f3f3f;
for(int i=1;i<=m;i++){// Get rid of a pair of friends , And the number of their friends is even
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++){// Remove one person , And his friends are odd
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
Meaning and requirements : Given
n*mMatrix , existingkPigment , Each pigment can be useda[i]Time . Ask if there is a dyeing method , You can make every lattice in the matrix , At least three of the four grids around it are the same color as it .
Ideas : You can draw your own picture and try it , Finally found the same color pigments , You can only dye at least two rows or two columns . So direct force dyeing by row and column .
Code :
#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];// How many lines can each dye dye dye
b[i]=c[i];// How many columns can each dye dye dye
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;
}
边栏推荐
- vlan间路由(讲解+验证)
- 漏风的小棉袄……
- Will Flink CDC constantly occupy Oracle's memory by extracting Oracle's data, and finally cause oracle-040
- (2022 Niuke multi school III) a-ancestor (LCA)
- Bash: 创建返回布尔类型值的函数
- C语言 pthread_cleanup_push()和pthread_cleanup_pop()函数(用于临界资源程序段中发生终止动作后的资源清理任务,以免造成死锁,临界区资源一般上锁)
- Top ten interview questions for software testing (with answers and analysis)
- yhb_sysbench
- Introduction to network -- overview of VLAN and trunk
- IO中节点流和处理流的理解学习
猜你喜欢

(2022 Hangdian multi school III) 1009.package delivery (greedy)

Use reflection to dynamically modify annotation attributes of @excel

Array method and loop in JS

VLAN trunk experiment

docker安装MySQL8.0.28

冰冰学习笔记:类与对象(中)

Overall dichotomy?

Li Mu hands-on learning, in-depth learning, V2 transformer and code implementation

flink1.14 sql基础语法(一) flink sql表查询详解

Introduction to network -- overview of VLAN and trunk
随机推荐
在Perl程序中暴露Prometheus指标
Quickly update the information in a field in kettle
在mac中使用docker来搭建oracle数据库服务器
Using docker in MAC to build Oracle database server
腾讯云服务器SSH链接自动断开解决方法
Use of tigervnc
Single arm routing (explanation + experiment)
Want to sink into redis hash and write in the attributes and values of the object. Do the bosses have a demo?
SQLite 常用功能整合
在kettle中快速更新一个字段中的信息
Expose Prometheus metrics in Perl programs
ADB instruction sorting
Array method and loop in JS
网络入门——vlan及trunk概述
Use Popen to execute a command and get the return result
Chapter 6 Shell Logic and Arithmetic
C# Winfrom 常用功能整合-2
ARP broadcasting practice cases
Analysis of memory structure of C program code
js正则表达式实现每三位数字加一个逗号
