传送门

参考资料

  [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. python 定义子类

  2. Android Binder设计与实现 – 设计篇

    摘要 Binder是Android系统进程间通信(IPC)方式之一.Linux已经拥有管道,system V IPC,socket等IPC手段,却还要倚赖Binder来实现进程间通信,说明Binder ...

  3. nodeJs学习-11 multer中间件,解析post文件,上传文件

    const express=require('express'); const bodyParser=require('body-parser'); const multer=require('mul ...

  4. [asp.net]登录协同工作平台安全解决方式

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/david_520042/article/details/25372207 [摘要]公司领导说登录验证 ...

  5. 13-4 jquery操作标签(文本,属性,class,value)

    一 文本操作 $().html() $().text() 文本赋值操作 $().html("") $().text("") 二 属性操作 $().attr(属性 ...

  6. python 处理图像出现The lower bounary is neither an array of the same size and same type as src, nor a scalar in function inRange

    在用python处理图像过程中出现如下错误 导致这个错误的原因是im是二维,而lower_green和upper_green是三维,所以无法用inRange处理. 由上图可以看出image本来是具有高 ...

  7. 利用伪类选择器与better-scroll的on事件所完成的上拉加载

    之前给大家分享过一篇上拉加载 利用了better-scroll的pullUpDown 和DOM元素的删除添加  感觉那样不太好 今天给大家分享一个不同的上拉加载思想 代码如下 class List { ...

  8. Android 开源库StickyListHeadersListView来实现ListView列表分组效果

    项目中有一新的需求,要求能像一些Android机带"联系人列表"一样,数据可以自动分组,且在列表滑动过程中,列表头固定在顶部,效果图如下: 下面就带大家实现上面的效果, 首先,我们 ...

  9. @noi.ac - 489@ shuffle

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 n 的序列 s1,s2,-,sn,它有 2^n− ...

  10. SuperSocket证书节点新增配置属性 "storeLocation"

    你可以指定你想要加载的证书的存储地点: <certificate storeName="My" storeLocation="LocalMachine" ...