传送门

参考资料

  [1]: the Chinese Editoria

A. Nauuo and Votes

•题意

  x个人投赞同票,y人投反对票,z人不确定;

  这 z 个人由你来决定是投赞同票还是反对票;

  判断 x 与 y 的相对大小是否确定?

题解

  如果 x == y && z == 0,输出 '0';

  如果 x-y > z,输出 '+';

  如果 y-x > z,输出 '-';

  反之,输出 '?';

Code

 #include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define memF(a,b,n) for(int i=0;i <= n;a[i++]=b);
const int maxn=1e3+; int x,y,z; char *Solve()
{
if(x == y && z == )
return "";
if(x-y > z)
return "+";
if(y-x > z)
return "-";
return "?";
}
int main()
{
// freopen("C:\\Users\\hyacinthLJP\\Desktop\\in&&out\\contest","r",stdin);
scanf("%d%d%d",&x,&y,&z);
puts(Solve()); return ;
}

B.Nauuo and Chess(构造)

题意

  给你 n 个棋子,求满足 "for all pairs of pieces i and j, |ri−rj|+|ci−cj| ≥ |i−j|."的最小的方形棋盘的列;

  方形棋盘的右下角(m,m)与左上角(1,1)的距离为 2×(m-1);

题解

  ①找到 2×(m-1) ≥ n-1 的最小的 m;

  ②将 1~n-1 个棋子从第一行开始填充,第一行填充完,填充最后一列;

•Code

 #include<bits/stdc++.h>
using namespace std;
#define memF(a,b,n) for(int i=0;i <= n;a[i++]=b);
#define INF 0x3f3f3f3f
const int maxn=2e5+; int n; void Solve()
{
int m=(n+)/;
printf("%d\n",m);
int x=,y=;
for(int i=;i < n;++i)
{
printf("%d %d\n",x,y);
if(y < m)///先填充第一行
y++;
else
x++;
}
printf("%d %d\n",m,m);
}
int main()
{
scanf("%d",&n);
Solve(); return ;
}

C. Nauuo and Cards(贪心)

题意

  有 2n 张牌,其中 n 张标号 1~n,其余 n 中为空牌;

  从这 2n 张牌中拿出 n 张放在手中,剩余的 n 张摞在桌子上(牌堆);

  你可以进行如下操作:

    将手中的任意一张牌插入到牌堆的底部,并将牌堆顶端的牌放入手中;

  求最少的操作,使得摞在桌子上的 n 张牌从顶端到底端为 1,2,....,n;

题解

  

  第一句话很好理解,主要是 “答案为 max(...)”这句话不太好理解,下面说说我的进一步理解:

  最终结果就是 1~n 摞在桌子上,并且有序;

  那么,存在牌k,在经过操作后,使得[1,2,...,k]在牌堆的底端,并且接下来的操作只用标号为[k+1,....,n]的牌,将其依次插入牌堆的底端;

  那么,这种情况下,答案就为 p[k]+1+n-k;

  其中 p[k]+1 是将牌 k 插入牌堆底端需要的最小操作,n-k是将[k+1,....,n]依次插入牌堆的最小操作;

Code

 #include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=2e5+; int n;
int a[maxn];
int b[maxn];
int p[maxn];///p[i]:第i张牌在b中的位置,如果在a中,那么p[i]=0; int F()///判断是否可以只将标号牌插入牌堆的底端使得最终状态满足条件
{
if(!p[])
return INF;
int cur=;
for(;p[cur] == p[]+cur-;cur++);
if(p[cur-] == n)///[1,2,...,cur-1]在b中最后的位置
{
int k=cur;
/**
在依次将第k(k∈[cur,n])张牌插入底部的时候要确保k在手上
如何确保k在手上呢?
假设[cur,k-1]成功插入到底部;
那么,这k-cur牌的插入势必会使得b中的前k-cur张牌拿到手中;
那么,只要b中前k-cur张牌含有k就行;
也就是p[k]<=k-cur;
*/
for(;k <= n && p[k] <= k-cur;k++);
if(k > n)///如果k=n+1,那么只操作[cur,n]便可满足条件
return n-(cur-);
}
return INF;
}
int G()
{
/**
①如果[1,..,i]中标号为x的牌,x在b中的位置在i之后
也就是说 x<i,p[x]>p[i];
那么 p[x]+1+n-x > p[i]+1+n-i;
对于这种情况,ans只会取x对应的操作次数
②如果经过p[i]+1次操作后使得[1,...i]插入牌堆的底端
但是,i之后存在标号为x,y的牌,x<y,p[x]>p[y]
那么,[i+1,...,n]是没法依次插入牌堆的
但,答案会是p[i]+1+n-i吗?
易得p[x] >= p[i]+2
第i张牌的操作次数为 p[i]+1+n-i;
第x张牌的操作次数为 p[x]+1+n-x;
两者做差得 p[x]+1+n-x-(p[i]+1+n-i)=p[x]-p[i]+i > 0
所以,ans只会取x对应的操作次数,而不会取i对应的操作次数
*/
int ans=;
for(int i=;i <= n;++i)
ans=max(ans,p[i]++n-i);
return ans;
}
int main()
{
scanf("%d",&n);
for(int i=;i <= n;++i)
{
scanf("%d",a+i);
p[a[i]]=;
}
for(int i=;i <= n;++i)
{
scanf("%d",b+i);
p[b[i]]=i;
}
printf("%d\n",min(F(),G())); return ;
}

•二次理解2019.10.21

  因为明天要帮老师讲有关贪心的实验课,今天就将之前做的贪心的题复习了一下;

  对这道题有了新的理解;

  将所有操作分为两类:

    (1)牌面为 1 的牌从手中打到桌子上

    (2)牌面为 1 的牌在桌子上,并且在不打空白牌的情况下就可以完成

  首先判断(2)是否满足,如果满足,那此时的解肯定是最优解;

  如果不满足(2),如何快速求解(1)对应的最优解呢?

  定义 $f_i$ 表示将牌放入手中所需的最小操作;

  因为要使得桌子上的牌连续,所以,在打出 1 这张牌后,紧接着要打 2 这张牌,接着是 3,......

  也就是说,$f_2 \leq f_1+1\ ,\ f_3 \leq f_1+2\ ,\cdots \ ,\ f_n \leq f_1+n-1$;

  所以说,要在 $max_{i=1}^{n} \ \ (f_i-(i-1))$ 后打出牌 1 才能确保接下来打出的牌依次为 2,3,4,....,n;

  所以,(1)的最优解为 $max_{i=1}^{n}\ (f_i-(i-1)) + n$;

•Code

 #include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+; int n;
int a[maxn];
int b[maxn];
int f[maxn]; int Calc()
{
if(f[] == )
return -;
for(int i=f[]+;i <= n;++i)
if(b[i] != b[i-]+)
return -; int ans=;
int k=;
for(int i=b[n]+;i <= n;++i)
{
if(f[i] > k)
return -;
ans++;
k++;
}
return ans;
}
int Solve()
{
int ans=Calc();
if(ans != -)
return ans; ans=f[];
for(int i=;i <= n;++i)
ans=max(ans,f[i]-(i-));
return ans+n;
}
int main()
{
scanf("%d",&n);
for(int i=;i <= n;++i)
{
scanf("%d",a+i);
f[a[i]]=;
}
for(int i=;i <= n;++i)
{
scanf("%d",b+i);
f[b[i]]=i;
}
printf("%d\n",Solve()); return ;
}

Codeforces Round #564 (Div. 2)的更多相关文章

  1. Codeforces Round #564 (Div. 1)

    Codeforces Round #564 (Div. 1) A Nauuo and Cards 首先如果牌库中最后的牌是\(1,2,\cdots, k\),那么就模拟一下能不能每次打出第\(k+i\ ...

  2. Codeforces Round #564 (Div. 2) C. Nauuo and Cards

    链接:https://codeforces.com/contest/1173/problem/C 题意: Nauuo is a girl who loves playing cards. One da ...

  3. Codeforces Round #564 (Div. 2) B. Nauuo and Chess

    链接:https://codeforces.com/contest/1173/problem/B 题意: Nauuo is a girl who loves playing chess. One da ...

  4. Codeforces Round #564 (Div. 2) A. Nauuo and Votes

    链接:https://codeforces.com/contest/1173/problem/A 题意: Nauuo is a girl who loves writing comments. One ...

  5. Codeforces Round #564 (Div. 2)B

    B. Nauuo and Chess 题目链接:http://codeforces.com/contest/1173/problem/B 题目 Nauuo is a girl who loves pl ...

  6. Codeforces Round #564 (Div. 2)A

    A. Nauuo and Votes 题目链接:http://codeforces.com/contest/1173/problem/A 题目 Nauuo is a girl who loves wr ...

  7. Codeforces Round #564 (Div. 2) D. Nauuo and Circle(树形DP)

    D. Nauuo and Circle •参考资料 [1]:https://www.cnblogs.com/wyxdrqc/p/10990378.html •题意 给出你一个包含 n 个点的树,这 n ...

  8. 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 ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. input的表单验证(不断更新中~~)

    1 手机号验证 <input type="tel" id="phone" name="phone" placeholder=" ...

  2. (转) Hibernate持久化类与主键生成策略

    http://blog.csdn.net/yerenyuan_pku/article/details/65462930 Hibernate持久化类 什么是持久化类呢?在Hibernate中持久化类的英 ...

  3. LeetCode136 Single Number, LeetCode137 Single Number II, LeetCode260 Single Number III

    136. Single Number Given an array of integers, every element appears twice except for one. Find that ...

  4. cat、head、tail、more和less命令(文件内容浏览)

    一.cat命令 cat命令连接文件并打印到标准输出设备上,cat经常用来显示文件的内容. 注意:当文件较大时,文本在屏幕上迅速闪过(滚屏),用户往往看不清所显示的内容.因此,一般用more等命令分屏显 ...

  5. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十章:阴影贴图

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十章:阴影贴图 本章介绍一种在游戏和应用中,模拟动态阴影的基本阴影 ...

  6. 2018年DDoS攻击全态势:战胜第一波攻击成“抗D” 关键

    2018年,阿里云安全团队监测到云上DDoS攻击发生近百万次,日均攻击2000余次.目前阿里云承载着中国40%网站,为全球上百万客户提供基础安全防御.可以说,阿里云上的攻防态势是整个中国攻防态势的缩影 ...

  7. BKDRHash算法的初步了解

    字符串hash最高效的算法,  搜了一下,  原理是: 字符串的字符集只有128个字符,所以把一个字符串当成128或更高进制的数字来看,当然是唯一的 这里unsigned不需要考虑溢出的问题,  不过 ...

  8. C++之加密机访问

    WininetHttp.h: #pragma once#include <iostream>#include <windows.h>#include <wininet.h ...

  9. Person Re-identification 系列论文笔记(三):Improving Person Re-identification by Attribute and Identity Learning

    Improving Person Re-identification by Attribute and Identity Learning Lin Y, Zheng L, Zheng Z, et al ...

  10. 微信小程序记录

    1.vs code 可以安装 Vetur-wepy 对代码高亮的提示. 2.取消swiper组件的手动滑动效果 在 swiper-item 中添加 catchtouchmove='catchTouch ...