Codeforces Round #531 (Div. 3)
A:瞎猜。
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
int n;
cin>>n;
if(n%==||n%==){
cout<<<<endl;
} else{
cout<<<<endl;
}
}
B:随便搞
#include <bits/stdc++.h>
using namespace std;
int n,k;
int a[],ans[];
set<int>s[];
void cloro(int id,int clo){
while (s[a[id]].count(clo)){
clo++;
if(clo==k+){
clo=;
}
}
ans[id]=clo;
s[a[id]].insert(clo);
}
int main() {
ios::sync_with_stdio(false);
cin>>n>>k;
for(int i=;i<=n;i++)
cin>>a[i];
int now = ;
bool flag = false;
for(int i=;i<=n;i++){
if(s[a[i]].size()==k){
cout<<"NO"<<endl;
exit();
}
cloro(i,now);
now++;
if(now==k+) {
now = ;
flag = true;
}
}
if(!flag&&now<k){
cout<<"NO"<<endl;
exit();
}
cout<<"YES"<<endl;
for(int i=;i<=n;i++)
cout<<ans[i]<<' ';
}
C:傻逼题
#include <bits/stdc++.h>
using namespace std;
int n,x,y,a[];
int dp[];
set<int> s;
int main() {
ios::sync_with_stdio(false);
cin>>n>>x>>y;
for(int i=;i<=n;i++)
cin>>a[i];
if(x>y){
cout<<n<<endl;
} else if(x<=y){
int num = ;
for(int i=;i<=n;i++){
if(a[i]<=x){
num++;
}
}
int ans = ;
while (num>){
ans++;
num-=;
}
cout<<ans<<endl;
}
}
D:贪心的 六种变换随便搞
我写的应该是有问题的,但是ppt了就不想改了,估计会掉。
upd 1/10 15:20 hhhh果然掉了 但是是我自己傻屌写错了,思路没有问题。 代码已更新
#include <bits/stdc++.h>
using namespace std;
string s;int n;
int a[];
void slove(int c01,int c02,int c10,int c12,int c20,int c21){
for(int i=n-;i>=;i--){
if(s[i]==''){
if(c02) {
s[i] = '';
c02--;
}
else if(c01) {
s[i] = '';
c01--;
} } else if(s[i]==''){
if(c12){
c12--;
s[i]='';
}
}
}
for(int i=;i<n;i++){
if(s[i]==''){
if(c20){
c20--;
s[i]='';
} else if(c21){
c21--;
s[i]='';
}
} else if(s[i]==''){
if(c10){
s[i]='';
c10--;
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin>>n>>s;
for(int i=;i<n;i++){
a[s[i]-'']++;
}
int c01=,c02=,c10=,c12=,c20=,c21=;
if(a[]>n/){
if(a[]>n/){
c02=a[]-n/;
c12=a[]-n/;
} else{
if(a[]>n/) {
c21 = a[] - n / ;
c01 = a[]-n/;
}
else {
c02 = n / - a[];
c01=n/-a[];
}
}
} else if(a[]>n/){
if(a[]>n/){
c10=a[]-n/;
c20=a[]-n/;
} else{
c10=n/-a[];
c12=n/-a[];
}
} else if(a[]>n/){
c20=n/-a[];
c21=n/-a[];
}
slove(c01,c02,c10,c12,c20,c21);
cout<<s<<endl;
}
E:每个数都可以确定一个区间,然后我们求不确定的区间的长度,答案就是 1<<(len-1)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = ;
int n;int a[];
ll qpow(ll a,ll x){
ll res = ;
while (x){
if(x&)
res=(res*a)%mod;
a=(a*a)%mod;
x/=;
}
return res;
}
map<int,int> m;
vector<int> v [];
int pre[];
int main() {
ios::sync_with_stdio(false);
cin>>n;
int id = ;
for(int i=;i<=n;i++) {
cin >> a[i];
if(m.count(a[i])){
v[m[a[i]]].push_back(i);
} else{
m[a[i]]=id;
v[id].push_back(i);
id++;
}
}
for(int i=;i<id;i++){
pre[v[i][]]++;
pre[v[i][v[i].size()-]]--;
}
ll cnt = ;
for(int i=;i<=n;i++){
pre[i]+=pre[i-];
if(pre[i]==)
cnt++;
}
cout<<qpow(,cnt-)<<endl;
}
F:状压dp。 数据范围很明显了。。 先预处理出来任意两行相邻的时候对答案的贡献,以及任意两行做头尾(就是第一行和最后一行)的贡献,然后dp,dp的时候枚举第一行是啥。
#include <bits/stdc++.h>
using namespace std;
int a[][],n,m;
int b[][],c[][],ans;
int f[<<][];
int slove(int id){
for(int i=;i<(<<n);i++)
for(int j=;j<n;j++)
f[i][j]=;
f[<<id][id]=1e9;
for(int i=;i<(<<n);i++){
for(int j=;j<n;j++){
if(i&(<<j)){
for(int k=;k<n;k++){
if(i&(<<k))continue;
f[i|(<<k)][k]=max(f[i|(<<k)][k],min(f[i][j],b[j][k]));
}
}
}
}
int ans = ;
for(int i=;i<n;i++){
if(i==id)continue;
ans = max(ans,min(c[id][i],f[(<<n)-][i]));
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=;i<n;i++){
for(int j=;j<m;j++){
cin>>a[i][j];
}
}
if(n==){
int ans = 1e9;
for(int i=;i<m-;i++)
ans = min(ans,abs(a[][i]-a[][i+]));
cout<<ans<<endl;
return ;
}
//预处理第i行与第j行相邻
for(int i=;i<n;i++){
for(int j=;j<n;j++){
b[i][j]=1e9;
for(int k=;k<m;k++){
b[i][j]=min(b[i][j],abs(a[i][k]-a[j][k]));
}
}
}
//i是第一行,j是最后一行
for(int i=;i<n;i++){
for(int j=;j<n;j++){
if(i==j) continue;
c[i][j]=1e9;
for(int k=;k<m-;k++)
c[i][j]=min(c[i][j],abs(a[i][k+]-a[j][k]));
}
}
int ans = ;
for(int i=;i<n;i++){
ans = max(ans,slove(i));
}
cout<<ans<<endl;
}
Codeforces Round #531 (Div. 3)的更多相关文章
- Codeforces Round #531 (Div. 3) ABCDEF题解
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
- Codeforces Round #531 (Div. 3) F. Elongated Matrix(状压DP)
F. Elongated Matrix 题目链接:https://codeforces.com/contest/1102/problem/F 题意: 给出一个n*m的矩阵,现在可以随意交换任意的两行, ...
- Codeforces Round #531 (Div. 3) E. Monotonic Renumeration (构造)
题意:给出一个长度为\(n\)的序列\(a\),根据\(a\)构造一个序列\(b\),要求: 1.\(b_{1}=0\) 2.对于\(i,j(i\le i,j \le n)\),若\(a_{i ...
- Codeforces Round #531 (Div. 3) D. Balanced Ternary String (贪心)
题意:给你一个长度为\(3*n\)的字符串,要求修改最少的次数,使得字符串中\(0,1,2\)的个数相同,并且在最少次数的情况下使字典序最小. 题解:贪心,\(0\)一定放在前面,\(1\)和\(2\ ...
- Codeforces Round #531 (Div. 3) C. Doors Breaking and Repairing (博弈)
题意:有\(n\)扇门,你每次可以攻击某个门,使其hp减少\(x\)(\(\le 0\)后就不可修复了),之后警察会修复某个门,使其hp增加\(y\),问你最多可以破坏多少扇门? 题解:首先如果\(x ...
- Codeforces Round #531 (Div. 3) B. Array K-Coloring (结构体排序)
题意:给你\(n\)个数字,用\(k\)种颜色给他们涂色,要求每个数字都要涂,每种颜色都要用,相同的数字不能涂一样的颜色. 题解:用结构体读入每个数字和它的位置,然后用桶记录每个数字出现的次数,判断是 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- 咏南中间件支持JWT TOKEN
咏南中间件支持JWT TOKEN
- MYSQL千万级数据量的优化方法积累
1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...
- Unity Inspector面板常用的属性
在扩展Unity的时候,往往会用到一些属性,这里将常用的列一下. 1.属性只读: #if UNITY_EDITOR using UnityEditor; #endif using UnityEngin ...
- Huawei® ENSP & VRP CheatSheet
#################### 系统命令 #################### system-view sysname display current-configuration und ...
- 第六周周赛——AK机会不易得,好好把握题解(出自HDU5650,codeforces 616A,624A,659A,655A,658A)
A题: A题题目链接 题目描写叙述: 位运算 TimeLimit:1000MS MemoryLimit:65536KB 64-bit integer IO format:%I64d Problem ...
- shell编程学习笔记(十二):Shell中的break/continue跳出循环
在循环遍历中,可以添加对应判断条件跳出循环,跳出循环可以使用break/continue,这个跟java语言是一样的,break是指跳出整个循环,continue是指跳出当前循环体,继续下一项循环. ...
- C#读取Excel文件的简单方法
一.简述 本文讲C#通过第三方库读取Excel的最简单的方法,下文给一个读取行数的例子. 二.依赖 引入nuget.org包如下: <?xml version="1.0" e ...
- yarn upgrade
更新一个依赖 yarn upgrade 用于更新包到基于规范范围的最新版本 yarn upgrade --latest # 忽略版本规则,升级到最新版本,并且更新 package.json .
- Huginn及环境搭建
博客搬迁至https://blog.wangjiegulu.com RSS订阅:https://blog.wangjiegulu.com/feed.xml Huginn 及环境搭建 什么是 Hugin ...
- VS2017打开VS2010项目报 “找不到*.xaml”错误
VS2017打开VS2010项目报 “找不到*.xaml”错误.详细如下: 未处理System.IO.IOExceptionMessage: “System.IO.IOException”类型的未经处 ...