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名学生,方阵的行数 ... 
随机推荐
- [翻译] AYVibrantButton
			AYVibrantButton https://github.com/a1anyip/AYVibrantButton AYVibrantButton is a stylish button with ... 
- Redis学习---Redis操作之有序集合
			有序集合,在集合的基础上,为每元素排序:元素的排序需要根据另外一个值来进行比较,所以,对于有序集合,每一个元素有两个值,即:值和分数,分数专门用来做排序. zadd(name, *args, **kw ... 
- Entity Framework的基本操作
			一.使用基本的方法进行增删改查 二.使用状态进行增删改查,即使用基类对象进行操作 三.多个表同时进行添加 添加数据后获取自动增长 ... 
- Centos7+Mysql80安装+远程链接开启
			CentOS7安装mysql80 下载repo源 在xshell运行命令 # wget http://repo.mysql.com/mysql80-community-release-el7.rpm ... 
- [2018HN省队集训D5T2] party
			[2018HN省队集训D5T2] party 题意 给定一棵 \(n\) 个点以 \(1\) 为根的有根树, 每个点有一个 \([1,m]\) 的权值. 有 \(q\) 个查询, 每次给定一个大小为 ... 
- 全局变量是列表list 的改变,  竟然在局部,用append 就可以了..... 不用global  sth...
			lst = ["麻花藤", "刘嘉玲", "詹姆斯"]def func(): lst.append("⻢云云") # 对 ... 
- 【原创】uwsgi中多进程+多线程原因以及串行化accept() - thunder_lock说明
			如有不对,请详细指正. 最近再研究uwsgi如何部署python app,看uwsgi的文档,里面有太多的参数,但每个参数的解释太苍白,作为菜鸟的我实在是不懂.想搞清楚uwsgi的工作原因以及里面的一 ... 
- 算法题:整形数组找a和b使得a+b=n
			题目: 数组 A 由 1000 万个随机正整数 (int) 组成,设计算法,给定整数 n,在 A 中找出 a 和 b,使其符合如下等式: n = a + b 解题思路: 1. 1000w个随机正整数占 ... 
- NSKeyValueObserving.m
			https://github.com/farcaller/cocotron/blob/af740de86c9bee84c59ffc74d27e5df9e22e1391/Foundation/NSKey ... 
- 浏览器地址栏运行JavaScript代码
			这个很多人应该还是知道的,在浏览器地址栏可以直接运行JavaScript代码,做法是以javascript:开头后跟要执行的语句.比如: javascript:alert('hello from ad ... 
