noip2017普及题解
https://www.luogu.org/problemnew/show/3954
https://www.luogu.org/problemnew/show/3955
https://www.luogu.org/problemnew/show/3956
https://www.luogu.org/problemnew/show/3957
T1
甚至不想用c++写
a,b,c=map(int,input().split(' '))
print((a+a+b+b+b+c+c+c+c+c)//10)
T2
乱水
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cctype>
#define rg register
#define il inline
#define vd void
il int gi(){
rg int x=0;rg bool flg=0;rg char ch=getchar();
while(!isdigit(ch)){if(ch=='-')flg=1;ch=getchar();}
while(isdigit(ch))x=x*10-'0'+ch,ch=getchar();
return flg?-x:x;
}
int ans[10000001];
il vd checkmn(int&a,int b){if(b<a)a=b;}
int main(){
// freopen("librarian.in","r",stdin);
// freopen("librarian.out","w",stdout);
int n=gi(),orz,q=gi();
for(rg int i=0;i<10000001;++i)ans[i]=19260817;
while(n--){
orz=gi();
checkmn(ans[orz],orz);
checkmn(ans[orz%10000000],orz);
checkmn(ans[orz%1000000],orz);
checkmn(ans[orz%100000],orz);
checkmn(ans[orz%10000],orz);
checkmn(ans[orz%1000],orz);
checkmn(ans[orz%100],orz);
checkmn(ans[orz%10],orz);
}
for(rg int i=0;i<10000001;++i)if(ans[i]==19260817)ans[i]=-1;
while(q--)gi(),orz=gi(),printf("%d\n",ans[orz]);
return 0;
}
T3
dij
还有BFS/SPFA/DFS/DP...
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cctype>
#include<queue>
#include<cstring>
#define rg register
#define il inline
#define vd void
il int gi(){
rg int x=0;rg bool flg=0;rg char ch=getchar();
while(!isdigit(ch)){if(ch=='-')flg=1;ch=getchar();}
while(isdigit(ch))x=x*10-'0'+ch,ch=getchar();
return flg?-x:x;
}
const int maxn=101;
int col[maxn][maxn];
struct orzyyb{int x,y;bool col;};
int f[maxn][maxn][2];
bool vis[maxn][maxn][2];
il bool operator <(const orzyyb&a,const orzyyb&b){return f[a.x][a.y][a.col]>f[b.x][b.y][b.col];}
std::priority_queue<orzyyb>que;
const int X[]={0,0,0,1,-1},Y[]={0,1,-1,0,0};
int main(){
// freopen("chess.in","r",stdin);
// freopen("chess.out","w",stdout);
int n=gi(),m=gi();
int x,y,xx,yy,c;
memset(col,-1,sizeof col);
memset(f,63,sizeof f);
while(m--)x=gi(),y=gi(),col[x][y]=gi();
que.push((orzyyb){1,1,(bool)col[1][1]});
f[1][1][col[1][1]]=0;
orzyyb p;
while(!que.empty()){
p=que.top();que.pop();
x=p.x,y=p.y,c=p.col;
if(vis[x][y][c])continue;
vis[x][y][c]=1;
for(rg int i=1;i<5;++i){
xx=x+X[i],yy=y+Y[i];
if(xx<1||xx>n||yy<1||yy>n)continue;
if(~col[xx][yy]){
if(f[xx][yy][col[xx][yy]]>f[x][y][c]+(c^col[xx][yy])){
f[xx][yy][col[xx][yy]]=f[x][y][c]+(c^col[xx][yy]);
que.push((orzyyb){xx,yy,(bool)col[xx][yy]});
}
}else if(~col[x][y]){
if(f[xx][yy][0]>f[x][y][c]+(c^0)+2){
f[xx][yy][0]=f[x][y][c]+(c^0)+2;
que.push((orzyyb){xx,yy,0});
}
if(f[xx][yy][1]>f[x][y][c]+(c^1)+2){
f[xx][yy][1]=f[x][y][c]+(c^1)+2;
que.push((orzyyb){xx,yy,1});
}
}
}
}
int ans=std::min(f[n][n][0],f[n][n][1]);
if(ans==1061109567)ans=-1;
printf("%d\n",ans);
return 0;
}
T4
太套路了
显然答案单调,所以二分k
check用动态规划
一个状态到下一个状态,转移过来的区间会右移(不会左移),所以单调队列优化
套路的死
PS.check加个优化快一倍
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cctype>
#define rg register
#define il inline
#define vd void
typedef int mainint;
#define int long long
il int gi(){
rg int x=0;rg bool flg=0;rg char ch=getchar();
while(!isdigit(ch)){if(ch=='-')flg=1;ch=getchar();}
while(isdigit(ch))x=x*10-'0'+ch,ch=getchar();
return flg?-x:x;
}
const int maxn=500010;
int n,x[maxn],s[maxn];
il bool dp(int l,int r,int k){
--k;
static int f[maxn],que[maxn];
int hd=0,tl=0,q=1,ret=-1e18;
for(rg int i=1;i<=n;++i){
while(x[i]-x[q]>=l){
while((hd^tl)&&f[que[tl-1]]<=f[q])--tl;
que[tl++]=q++;
}
while((hd^tl)&&x[i]-x[que[hd]]>r)++hd;
if(x[i]>=l&&x[i]<=r)f[i]=s[i];
else f[i]=-1e18;
if(hd^tl)f[i]=std::max(f[i],f[que[hd]]+s[i]);
if(f[i]>k)return 0;
}
return 1;
}
mainint main(){
// freopen("jump.in","r",stdin);
// freopen("jump.out","w",stdout);
n=gi();
int d=gi(),k=gi();
for(rg int i=1;i<=n;++i)x[i]=gi(),s[i]=gi();
if(dp(1,x[n],k)){puts("-1");return 0;}
int l=0,r=x[n],mid;
while(l<r){
mid=(l+r)>>1;
if(dp(std::max(1ll,d-mid),std::min(d+mid,x[n]),k))l=mid+1;
else r=mid;
}
printf("%lld\n",l);
return 0;
}
noip2017普及题解的更多相关文章
- NOIP2017普及组解题报告
刚参加完NOIP2017普及,只考了210,于是心生不爽,写下了这篇解题报告...(逃 第一次写博,望dalao们多多指导啊(膜 第一题score,学完helloworld的人也应该都会吧,之前好多人 ...
- noip2017普及 兔纸游玩记
初中的最后一场比赛...就这样结束了吧...QAQ时间...真够快的qwq 应该是初中的最后一篇游记了吧,尽量写多点... 这是一篇,初三 老年菜兔的 noip2017 普及游玩记吧! DAY 0 ...
- [NOIP2017普及组]跳房子(二分,单调队列优化dp)
[NOIP2017普及组]跳房子 题目描述 跳房子,也叫跳飞机,是一种世界性的儿童游戏,也是中国民间传统的体育游戏之一. 跳房子的游戏规则如下: 在地面上确定一个起点,然后在起点右侧画 nn 个格子, ...
- 「LOJ 6373」NOIP2017 普及组题目大融合
NOIP2017 普及组题目大融合 每个读者需要有某个后缀的书,可以暴力map,复杂度\(o(9*nlog(n))\),也可以反串建trie树,复杂度\(o(9*n)\). 故可以求出需要的最少的RM ...
- P3956 [NOIP2017 普及组] 棋盘
P3956 [NOIP2017 普及组] 棋盘 题目 题目描述 有一个 m×m 的棋盘,棋盘上每一个格子可能是红色.黄色或没有任何颜色的.你现在要从棋盘的最左上角走到棋盘的最右下角. 任何一个时刻,你 ...
- NOIP2017普及组T2题解
还是神奇的链接 上面依然是题目. 这道题依然很简单,比起2015年的普及组t2好像还是更水一些. 不过这道题能讲的比第一题多. 我们一起来看一下吧! 这一题,我们首先将书的编号全部读入,存在一个数组里 ...
- NOIP2017普及组T1题解
神奇的链接 上面时题目. 其实不得不说,这一题很水,比2015年的第一题水多了. 直接按题目套公式就行了,当然你也可以像我一样化简一下. 直接看代码: #include<cstdio> # ...
- NOIP2017普及组比赛总结
期中考总结&NOIP2017总结 2017年11月11日,我第二次参加NOIP普及组复赛.上一年,我的得分是250分,只拿到了二等奖.我便把目标定为拿到一等奖,考到300分以上. 早上8点多, ...
- NOIP2017 列队 题解报告【56行线段树】
题目描述 Sylvia 是一个热爱学习的女♂孩子. 前段时间,Sylvia 参加了学校的军训.众所周知,军训的时候需要站方阵. Sylvia 所在的方阵中有n \times mn×m名学生,方阵的行数 ...
随机推荐
- 使用Thunderbird时你可能会用到的技巧
1.添加qq邮箱账号 (1).开启IMAP/SMTP服务 先在QQ网页邮箱-设置-账户:开启IMAP/SMTP服务(2). Thunderbird 里设定端口(非POP):IMAP:imap.qq.c ...
- 纯css3云彩动画效果
效果描述: 纯CSS3实现的云彩动画飘动效果 非常逼真实用 使用方法: 1.将body中的代码部分拷贝到你的页面中 2.引入对应的CSS文件即可
- ali验证码推送接口调用
/** * 发送接口 * @param $info 发送信息的某些参数 * @return bool */ public function send($info) { $config = target ...
- Hive学习之路 (七)Hive的DDL操作
库操作 1.创建库 语法结构 CREATE (DATABASE|SCHEMA) [IF NOT EXISTS] database_name [COMMENT database_comment] //关 ...
- (十一)T检验-第二部分
了解什么是有效大小,尝试一个单一样本t检验的完整示例. 效应量 调查研究的一个重要方面是效应量,在实验性研究中或存在处理变量的研究中,效应量是指处理效应的大小,意思很直观: 在非实验性研究中,效应量是 ...
- 多线程之Thread类
Java并发编程:Thread类的使用 在前面2篇文章分别讲到了线程和进程的由来.以及如何在Java中怎么创建线程和进程.今天我们来学习一下Thread类,在学习Thread类之前,先介绍与线程相关知 ...
- Lambda表达式学习(2)
在. net3. 5里面 , 委托的定义和实现被大大的简化了!使用关键字Func或Action就可以定义一个委托 , 使用拉姆达表达式就可以实现一个具体的委托. Func关键字是用来定义一个有返回值的 ...
- launch edge 和 latch edge 延迟
本文转自 http://www.cnblogs.com/inet2012/archive/2012/03/07/2384149.html launch edge和latch edge分别是指一条路径的 ...
- ZooKeeper(二)Java API使用
ZooKeeper官网提供了Java和C的API. 本文使用Java API来实现ZooKeeper的基本操作. 前言 下图中的Replicated Database是包含完整数据树(entire d ...
- 443 D. Teams Formation
http://codeforces.com/contest/879/problem/D This time the Berland Team Olympiad in Informatics is he ...