NOIP 2013 提高组 合集

D1 T1 转圈游戏

快速幂裸题

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; typedef long long ll;
ll mod;
ll qpow(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1) ans=(ans*x)%mod;
y>>=1;
x=(x*x)%mod;
}
return ans;
}
int main()
{
ll m,k,x; cin >> mod >> m >> k >> x ;
// printf("%lld\n",qpow(10,10));
printf("%lld\n",(x+qpow(10,k)%mod*m%mod)%mod);
return 0;
}

D1 T2 火柴排队

我们显然可以固定一个序列,因为我们可以通过相对的交换来等价地达到目的。

所以只需要求离散化后的逆序对即可。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define mod 99999997
#define N 100010
using namespace std; typedef long long ll;
ll tree[N<<1],n;
inline char nc() {static char *p1,*p2,buf[100000]; return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}
ll rd() {ll x=0; char c=nc(); while(!isdigit(c)) c=nc(); while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=nc(); return x;}
struct Node
{
ll len; int id,now;
}a[N],b[N];
inline bool cmp_len(const Node &x,const Node &y) {return x.len<y.len;}
// inline bool cmp_id(const Node &x,const Node &y) {return x.id<y.id;}
inline int lowbit(int x) {return x&(-x);}
void update(int x)
{
for(int i=x;i>=1;i-=lowbit(i)) (tree[i]+=1)%=mod;
}
ll query(int x)
{
ll ans=0; for(int i=x;i<=n+1;i+=lowbit(i)) (ans+=tree[i])%=mod;
return ans;
}
int main()
{
n=rd();
for(int i=1;i<=n;i++)
{
a[i].len=rd();
a[i].id=i;
}
for(int i=1;i<=n;i++)
{
b[i].len=rd();
b[i].id=i;
}
sort(a+1,a+n+1,cmp_len); sort(b+1,b+n+1,cmp_len);
// puts("Fuck"); for(int i=1;i<=n;i++) printf("%lld ",b[i].id); puts("");
for(int i=1;i<=n;i++)
{
a[a[i].id].now=b[i].id;
}
// for(int i=1;i<=n;i++) printf("%d\n",a[i].now); puts("");
ll ans=0;
for(int i=1;i<=n;i++)
{
update(a[i].now);
(ans+=query(a[i].now+1))%=mod;
}
printf("%lld\n",ans);
return 0;
}

D1 T3 运输计划

离线+树剖+线段树+并查集

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 100010
using namespace std;
struct Node
{
int x,y,z;
}a[N]; int n,m;
int head[N],to[N<<1],val[N<<1],nxt[N<<1],tot,F[N],dep[N],f[N][20],g[N][20]; bool vis[N];
inline bool cmp(const Node &x,const Node &y) {return x.z>y.z;}
inline char nc() {static char *p1,*p2,buf[100000]; return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}
int rd() {int x=0; char c=nc(); while(!isdigit(c)) c=nc(); while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=nc(); return x;}
inline void add(int x,int y,int z) {to[++tot]=y; val[tot]=z; nxt[tot]=head[x]; head[x]=tot;}
int find(int x) {return F[x]==x?x:F[x]=find(F[x]);}
void dfs(int pos,int fa)
{
f[pos][0]=fa; dep[pos]=dep[fa]+1; for(int i=1;i<=18;i++) f[pos][i]=f[f[pos][i-1]][i-1];
for(int i=head[pos];i;i=nxt[i]) if(to[i]!=fa)
{
dfs(to[i],pos);
}
}
void dfs2(int pos,int fa)
{
for(int i=head[pos];i;i=nxt[i]) if(to[i]!=fa)
{
g[to[i]][0]=val[i];
for(int j=1;j<=18;j++) g[to[i]][j]=min(g[to[i]][j-1],g[f[to[i]][j-1]][j-1]);
dfs2(to[i],pos);
}
}
int calc(int x,int y)
{
// printf("%d %d\n",x,y);
int ans=0x7f7f7f7f;
if(dep[x]<dep[y]) swap(x,y);
// printf("%d %d %d\n",x,y,ans);
for(int i=18;~i;i--)
{
// printf("%d %d %d\n",x,y,ans);
if(dep[f[x][i]]>=dep[y]) ans=min(ans,g[x][i]),x=f[x][i];
}
if(x==y) return ans;
for(int i=18;~i;i--)
{
// printf("%d %d %d\n",x,y,ans);
if(f[x][i]!=f[y][i]) ans=min(ans,min(g[x][i],g[y][i])),x=f[x][i],y=f[y][i];
}
// printf("%d %d %d\n",x,y,ans);
return min(ans,min(g[x][0],g[y][0]));
}
inline bool merge(int x,int y)
{
x=find(x); y=find(y);
if(x==y) return true;
F[x]=y; return false;
}
void test()
{
for(int i=1;i<=3;i++)
{
for(int j=0;j<=18;j++) printf("%d ",g[i][j]);
puts("");
}
}
int main()
{
memset(g,0x7f,sizeof g); n=rd(),m=rd();
int x,y; for(int i=1;i<=n;i++) F[i]=i;
for(int i=1;i<=m;i++) a[i].x=rd(),a[i].y=rd(),a[i].z=rd();
sort(a+1,a+m+1,cmp); for(int i=1;i<=m;i++)
{
if(!merge(a[i].x,a[i].y))
{
// printf("Shit %d %d %d\n",a[i].x,a[i].y,a[i].z);
add(a[i].x,a[i].y,a[i].z); add(a[i].y,a[i].x,a[i].z);
}
}
// printf("%d\n",find(1));
for(int i=1;i<=n;i++)
{
x=find(i);
if(!vis[x]) dfs(x,x),dfs2(x,x),vis[x]=1;
}
// test();
int q=rd(); for(int i=1;i<=q;i++)
{
x=rd(),y=rd(); if(find(x)!=find(y)) {puts("-1"); continue;}
printf("%d\n",calc(x,y));
}
return 0;
}

D2 T1 积木大赛

sb题

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int n,a; cin >> n ;
int last=0,ans=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a);
if(a>last) ans += (a-last);
last=a;
}
cout << ans << endl ;
return 0;
}

D2 T2 花匠

dp裸题

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 100010
int a[N],f[N][2];
inline char nc() {static char *p1,*p2,buf[100000]; return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}
int rd() {int x=0; char c=nc(); while(!isdigit(c)) c=nc(); while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=nc(); return x;}
int main()
{
int n=rd(); for(int i=1;i<=n;i++) a[i]=rd();
f[1][0]=f[1][1]=1;
for(int i=2;i<=n;i++)
{
if(a[i]>a[i-1]) f[i][0]=f[i-1][1]+1;
else f[i][0]=f[i-1][0];
if(a[i]<a[i-1]) f[i][1]=f[i-1][0]+1;
else f[i][1]=f[i-1][1];
}
printf("%d\n",max(f[n][0],f[n][1]));
return 0;
}

D2 T3 华容道

挖坑代填

NOIP2013 提高组合集的更多相关文章

  1. NOIP2011 提高组合集

    NOIP 2011 提高组合集 D1 T1 铺地毯 模拟,题目让你干啥你就干啥 #include <iostream> #include <cstdio> using name ...

  2. NOIP2010 提高组合集

    NOIP 2010 提高组合集 T1 机器翻译 模拟题,用一个栈模拟,桶记录即可. #include <iostream> #include <cstdio> #include ...

  3. NOIP2015 提高组合集

    NOIP 2015 提高组 合集 D1 T1 神奇的幻方 题目让你干啥你就干啥,让你咋走你就咋走就完事儿了 #include <iostream> #include <cstdio& ...

  4. NOIP2014 提高组合集

    NOIP 2014 提高组 合集 D1 T1 生活大爆炸版石头剪刀布 首先,先将两个人的猜拳序列都变得不小于n.然后逐个模拟.胜败什么的看表就行了. #include <iostream> ...

  5. NOIP2012 提高组合集

    NOIP 2012 提高组 合集 D1 T1 Vigenère 密码 模拟题,观察到两个数对应位置-1相加的和%26就是对应的字母,按照这个性质模拟即可. #include <iostream& ...

  6. [NOIp2013提高组]积木大赛/[NOIp2018提高组]铺设道路

    [NOIp2013提高组]积木大赛/[NOIp2018提高组]铺设道路 题目大意: 对于长度为\(n(n\le10^5)\)的非负数列\(A\),每次可以选取一个区间\(-1\).问将数列清零至少需要 ...

  7. [NOIP2013提高&洛谷P1966]火柴排队 题解(树状数组求逆序对)

    [NOIP2013提高&洛谷P1966]火柴排队 Description 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度. 现在将每盒中的火柴各自排成一列, 同一列火柴的高度互不相 ...

  8. NOIP2013提高问题求解T2(关于递推与递归)

    同步发表于我的洛谷博客. NOIP2013提高问题求解2: 现有一只青蛙,初始时在n号荷叶上.当它某一时刻在k号荷叶上时,下一时刻将等概率地随机跳到1,2,--,k号荷叶之一上,直到跳到第1号荷叶为止 ...

  9. [NOIP2013 提高组] 华容道 P1979 洛谷

    [NOIP2013 提高组] 华容道 P1979 洛谷 强烈推荐,更好的阅读体验 经典题目:spfa+bfs+转化 题目大意: 给出一个01网格图,和点坐标x,y空格坐标a,b,目标位置tx,ty要求 ...

随机推荐

  1. 洛谷P4887 第十四分块(前体)(二次离线莫队)

    题面 传送门 题解 lxl大毒瘤 我们考虑莫队,在移动端点的时候相当于我们需要快速计算一个区间内和当前数字异或和中\(1\)的个数为\(k\)的数有几个,而这个显然是可以差分的,也就是\([l,r]\ ...

  2. linux学习之路4 系统目录架构

    linux树状文件系统结构 bin(binary) 保存可执行文件 也就是保存所有命令 boot 引导目录 保存所有跟系统有关的引导程序 其中Vmlinux文件最为重要,是系统内核 dev 保存所有的 ...

  3. .net中RSA加密解密

    1.产生密钥: private static void CreateKey() { using (RSACryptoServiceProvider rsa = new RSACryptoService ...

  4. Troubleshooting Guide for ORA-12541 TNS: No Listener

    Server side checks (not platform specific): 1)  Check the result on the server using tnsping to the ...

  5. Asp.net:MVC认识

    用MVC框架好长一段时间,发现每天都是写业务代码,不想每天只为了工作而写代码,想把工作中认识的MVC框架,遇到的问题,有时候天天在用,但是不知道里面是什么东西,什么原理,为啥這样写等一系列问题.进行梳 ...

  6. java IO流技术 之 File

    IO流技术 概念:input - output 输入输出流: 输入:将文件读到内存中: 输出:将文件从内存中写出到其他地方 作用:主要就是解决设备和设备之间的数据传输问题. File :文件类的使用十 ...

  7. poj2502 Subway

    思路: 需要注意的地方:一条地铁线路并不一定和样例描述的那样是直的:同一条线路上的两个站点步行可能更快. 实现: #include <iostream> #include <cstd ...

  8. Unity笔记(3)自学第二天

    学习记录: 界面使用: 脚本使用: 脚本注意点:

  9. 联想 Z5S(L78071)免解锁BL 免rec 保留数据 ROOT Magisk Xposed 救砖 ZUI 10.5.370

    >>>重点介绍<<< 第一:本刷机包可卡刷可线刷,刷机包比较大的原因是采用同时兼容卡刷和线刷的格式,所以比较大第二:[卡刷方法]卡刷不要解压刷机包,直接传入手机后用 ...

  10. 携程transform放大效果

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...