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普及题解的更多相关文章

  1. NOIP2017普及组解题报告

    刚参加完NOIP2017普及,只考了210,于是心生不爽,写下了这篇解题报告...(逃 第一次写博,望dalao们多多指导啊(膜 第一题score,学完helloworld的人也应该都会吧,之前好多人 ...

  2. noip2017普及 兔纸游玩记

    初中的最后一场比赛...就这样结束了吧...QAQ时间...真够快的qwq 应该是初中的最后一篇游记了吧,尽量写多点... 这是一篇,初三 老年菜兔的 noip2017 普及游玩记吧! DAY 0  ...

  3. [NOIP2017普及组]跳房子(二分,单调队列优化dp)

    [NOIP2017普及组]跳房子 题目描述 跳房子,也叫跳飞机,是一种世界性的儿童游戏,也是中国民间传统的体育游戏之一. 跳房子的游戏规则如下: 在地面上确定一个起点,然后在起点右侧画 nn 个格子, ...

  4. 「LOJ 6373」NOIP2017 普及组题目大融合

    NOIP2017 普及组题目大融合 每个读者需要有某个后缀的书,可以暴力map,复杂度\(o(9*nlog(n))\),也可以反串建trie树,复杂度\(o(9*n)\). 故可以求出需要的最少的RM ...

  5. P3956 [NOIP2017 普及组] 棋盘

    P3956 [NOIP2017 普及组] 棋盘 题目 题目描述 有一个 m×m 的棋盘,棋盘上每一个格子可能是红色.黄色或没有任何颜色的.你现在要从棋盘的最左上角走到棋盘的最右下角. 任何一个时刻,你 ...

  6. NOIP2017普及组T2题解

    还是神奇的链接 上面依然是题目. 这道题依然很简单,比起2015年的普及组t2好像还是更水一些. 不过这道题能讲的比第一题多. 我们一起来看一下吧! 这一题,我们首先将书的编号全部读入,存在一个数组里 ...

  7. NOIP2017普及组T1题解

    神奇的链接 上面时题目. 其实不得不说,这一题很水,比2015年的第一题水多了. 直接按题目套公式就行了,当然你也可以像我一样化简一下. 直接看代码: #include<cstdio> # ...

  8. NOIP2017普及组比赛总结

    期中考总结&NOIP2017总结 2017年11月11日,我第二次参加NOIP普及组复赛.上一年,我的得分是250分,只拿到了二等奖.我便把目标定为拿到一等奖,考到300分以上. 早上8点多, ...

  9. NOIP2017 列队 题解报告【56行线段树】

    题目描述 Sylvia 是一个热爱学习的女♂孩子. 前段时间,Sylvia 参加了学校的军训.众所周知,军训的时候需要站方阵. Sylvia 所在的方阵中有n \times mn×m名学生,方阵的行数 ...

随机推荐

  1. Linux 下 python如何配置virtualenv

    .安装virtualenv pip3 install virtualenv pip install -i https://pypi.tuna.tsinghua.edu.cn/simple virtua ...

  2. 用以替换系统NSLog的YouXianMingLog

    用以替换系统NSLog的YouXianMingLog 这是本人自己使用并改良的用以替换系统NSLog的类,非常好用,以下是使用示例,现在开源出来并提供源码,好用的话顶一下吧^_^ 效果: YouXia ...

  3. Data Compression

    数据压缩 introduction 压缩数据可以节省存储数据需要的空间和传输数据需要的时间,虽然摩尔定律说集成芯片上的晶体管每 18-24 个月翻一倍,帕金森定律说数据会自己拓展来填满可用空间,但数据 ...

  4. javascript 的MD5代码备份,跟java互通

    var MD5 = function (string) {                   function RotateLeft(lValue, iShiftBits) {            ...

  5. python第十二课——for in循环

    1.for...in循环: 有两个使用场景: 场景一:for in和range对象配合使用 range对象的引入讲解 格式:range([start,end,step]): 特点:索引满足含头不含尾的 ...

  6. 学习python第三天之多行函数

    多行函数:(聚合函数/分组函数) 解释:多条数据进入,单条结果出来(多进单出) 1).max(obj):最大值 2).min(obj):最小值 3).sum(num):求和 4).avg(num):求 ...

  7. Python学习之路 (四)爬虫(三)HTTP和HTTPS

    HTTP和HTTPS HTTP协议(HyperText Transfer Protocol,超文本传输协议):是一种发布和接收 HTML页面的方法. HTTPS(Hypertext Transfer ...

  8. 预备作业二——有关CCCCC语言(・᷄ᵌ・᷅)

    有关CCCCC语言(・᷄ᵌ・᷅) 下面又到了回答老师问题的时候啦-(・᷄ᵌ・᷅) 有些问题正在深思熟虑中!敬请期待近期的不间断更新! 你有什么技能比大多人(超过90%以上)更好? 针对这个技能的获取你 ...

  9. cpu负载过高分析

    如何定位是哪个服务进程导致CPU过载,哪个线程导致CPU过载,哪段代码导致CPU过载? 步骤一.找到最耗CPU的进程 工具:top 方法: 执行top -c ,显示进程运行信息列表 键入P (大写p) ...

  10. P2280 [HNOI2003]激光炸弹

    题目描述 输入输出格式 输入格式: 输入文件名为input.txt 输入文件的第一行为正整数n和正整数R,接下来的n行每行有3个正整数,分别表示 xi,yi ,vi . 输出格式: 输出文件名为out ...