NOIP2013 题解
转圈游戏
题解:快速幂
#include <cstdio>
int n, m, k, x;
inline long long QuickPow(int a, int k, int MOD){
long long base = a, ret = ;
while (k){
if (k&) ret = (ret*base)%MOD;
base = (base*base)%MOD, k >>= ;
}
return ret;
}
int main(){
scanf("%d %d %d %d", &n, &m, &k, &x);
printf("%lld\n", (x%n+(m%n)*QuickPow(, k, n)%n)%n);
}
circle.cpp
火柴排队
题解:求逆序对(因为写不来归排就写的树状数组,怕TLE就蛋疼的加了一个读入优化)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = +;
const int MOD = ; int n, ans, c[MAXN], d[MAXN];
char cc; struct Match{
int v, n; friend bool operator < (const Match& A, const Match& B){
return A.v<B.v;
}
}a[MAXN], b[MAXN]; inline void add(int p, int v){
while (p<=n)
d[p] += v, p += (p&(-p));
} inline int sum(int p){
int ret = ;
while (p>)
ret += d[p], p -= (p&(-p));
return ret;
} inline int NextInt(){
int ret = ;
do cc = getchar();
while (cc< || cc>);
do ret *= , ret += (cc-), cc = getchar();
while (<=cc && cc<=);
return ret;
} int main(){
memset(d, , sizeof());
n = NextInt(), ans = ;
for (int i=; i<n; i++)
a[i].v = NextInt(), a[i].n = i+;
sort(a, a+n);
for (int i=; i<n; i++)
b[i].v = NextInt(), b[i].n = i+;
sort(b, b+n); for (int i=; i<n; i++)
c[a[i].n] = b[i].n; for (int i=; i<=n; i++)
add(c[i], ),
ans = (ans+i-sum(c[i]))%MOD;
printf("%d\n", ans);
}
match.cpp
货车运输
题解:先建一个最大生成树,再用lca乱搞一下就好了
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXL = ;
const int MAXN = +;
const int MAXM = +;
const int INF = 0x3f3f3f3f; int n, m, f[MAXN], nimo[MAXN][MAXL], an[MAXN][MAXL], dep[MAXN];
bool vis[MAXN];
char c; struct Edge{
int d, to;
Edge *next;
}e[MAXM], *head[MAXN]; struct Bary{
int u, v, d; friend bool operator < (const Bary& A, const Bary& B){
return A.d>B.d;
}
}bd[MAXM]; inline int NextInt(){
int ret = ;
do c = getchar();
while (c< || c>);
do ret *= , ret += (c-), c = getchar();
while (<=c && c<=);
return ret;
} inline int find(int x){
return x==f[x] ? x : f[x]=find(f[x]);
} int ne = ;
inline void AddEdge(int f, int t, int d){
e[ne].to = t, e[ne].d = d;
e[ne].next = head[f];
head[f] = e + ne++;
} inline void Add(int u, int v, int d){
f[find(u)] = find(v);
AddEdge(u, v, d), AddEdge(v, u, d);
} inline void BuildTree(int x){
vis[x] = true;
for (Edge *p=head[x]; p; p=p->next)
if (!vis[p->to])
an[p->to][] = x, nimo[p->to][] = p->d, dep[p->to] = dep[x]+, BuildTree(p->to);
} inline int swim(int &x, int ht){
int ret = INF;
for (int i=MAXL-; i>=; i--)
if (dep[an[x][i]]>=ht) ret = min(ret, nimo[x][i]), x = an[x][i];
return ret;
} inline int lca(int x, int y){
int ret = INF;
if (dep[x]^dep[y]) ret = dep[x]>dep[y] ? swim(x, dep[y]) : swim(y, dep[x]);
if (x==y) return ret;
for (int i=MAXL-; i>=; i--)
if (an[x][i]^an[y][i])
ret = min(ret, min(nimo[x][i], nimo[y][i])),
x = an[x][i], y = an[y][i];
return min(ret, min(nimo[x][], nimo[y][]));
} int main(){
memset(vis, false, sizeof(vis));
memset(an, , sizeof(an)); n = NextInt(), m = NextInt();
for (int i=; i<=n; i++)
f[i] = i;
for (int i=; i<m; i++)
bd[i].v = NextInt(), bd[i].u = NextInt(), bd[i].d = NextInt(); sort(bd, bd+m);
for (int i=; i<m; i++)
if (find(bd[i].u)^find(bd[i].v)) Add(bd[i].u, bd[i].v, bd[i].d);
for (int i=; i<=n; i++)
if (!vis[i]) dep[i] = , BuildTree(i), nimo[i][] = INF, an[i][] = i; for (int i=; i<MAXL; i++)
for (int j=; j<=n; j++)
an[j][i] = an[an[j][i-]][i-],
nimo[j][i] = min(nimo[j][i-], nimo[an[j][i-]][i-]); int Q, a, b;
scanf("%d", &Q);
while (Q--)
scanf("%d %d", &a, &b),
printf("%d\n", find(a)==find(b) ? lca(a, b) : -);
}
truck.cpp
积木大赛:
题解:模拟,ans = ∑max{0, a[i]-a[i-1]}
#include <cstdio>
int num, h[];
int max(int a,int b){
return a>b ? a : b;
}
int main(){
scanf("%d",&num);
for (int i=; i<num; i++)
scanf("%d", &h[i]);
long long ans = ;
for (int i=; i<num; i++)
ans += max(, h[i]-h[i-]);
printf("%lld",ans);
}
block.cpp
花匠:
题解:贪心,缩点,把满足的连这的一群点缩为一个
#include <cstdio>
const int MAXN = 1e6+; int n, Pri, cj, a[MAXN]; int main(){
scanf("%d", &n), Pri = , cj = ;
for (int i=; i<n; i++)
scanf("%d", a+i);
for (int i=; i<n; i++){
if (a[i]>a[i-] && cj!=) cj = , Pri ++;
if (a[i]<a[i-] && cj!=) cj = , Pri ++;
}
printf("%d", Pri);
}
flower.cpp
NOIP2013 题解的更多相关文章
- NOIP2013题解
NOIP2013题解 Day1 转圈游戏 circle 快速幂模板题. #include<iostream> using namespace std; int n,m,k,x; int f ...
- [NOIP补坑计划]NOIP2013 题解&做题心得
场上预计得分:100+100+100+100+100+60=560(省一分数线410) 五道傻逼题+一道大搜索题…… 题解: D1T1 转圈游戏 题面 水题送温暖~ #include<algor ...
- [NOIP2013提高&洛谷P1966]火柴排队 题解(树状数组求逆序对)
[NOIP2013提高&洛谷P1966]火柴排队 Description 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度. 现在将每盒中的火柴各自排成一列, 同一列火柴的高度互不相 ...
- NOIP2013 DAY2题解
DAY2 T1积木大赛 传送门 题目大意:每次可以选区间[l,r]加1,最少选几次,让每个位置有 它应有的高度. 题解:O(n)扫一遍就好了.后一个比前一个的高度低,那么前一个已经把它覆盖了, 如果高 ...
- [NOIP2013]华容道 题解(搜索)
[NOIP2013]华容道 [题目描述] 这道题根据小时候玩华容道不靠谱的经验还以为是并查集,果断扑街.考后想想也是,数据这么小一定有他的道理. 首先由于是最小步数,所以BFS没跑了.那么我们大可把这 ...
- [NOIP2013]华容道 题解
[NOIP2013]华容道 首先是一种比较显然的做法. 整个棋盘,除了起点,终点和空格,其他的方块是等价的. 对于终点,它始终不会变化,如果搜到终点结束搜索即可,所以我们不需要考虑终点. 所以需要考虑 ...
- 题解 【NOIP2013】转圈游戏
[NOIP2013]转圈游戏 Description n个小伙伴(编号从0到n-1)围坐一圈玩游戏.按照顺时针方向给n个位置编号,从0到n-1.最初,第0号小伙伴在第0号位置,第1号小伙伴在第1号位置 ...
- 题解【洛谷P1967】[NOIP2013]货车运输
题面 题解 注意到有一些限重很低的边不会被走到. 于是考虑建一棵最大生成树,在生成树上寻找答案. 设\(f[i][j]\)表示\(i\)的\(2^j\)级祖先,\(w[i][j]\)表示\(i\)到\ ...
- 题解【洛谷P1983】[NOIP2013]车站分级
题面 题解 不难想到拓扑排序 于是每一个等级高的向等级低的连一条边 考虑拓扑排序过程中的分层 对于每个点进行分层 于是答案就是这些点中的最大层数 然后就会RE 发现我们多连了一些重复的边 用一个标记数 ...
随机推荐
- iOS Storyboard全解析
来源:http://iaiai.iteye.com/blog/1493956 Storyboard)是一个能够节省你很多设计手机App界面时间的新特性,下面,为了简明的说明Storyboard的效果, ...
- XE6移动开发环境搭建之IOS篇(5):解决Windows和虚拟机下Mac OSX的共享问题(有图有真相)
网上能找到的关于Delphi XE系列的移动开发环境的相关文章甚少,本文尽量以详细的图文内容.傻瓜式的表达来告诉你想要的答案. 原创作品,请尊重作者劳动成果,转载请注明出处!!! 在安装XE6 PAS ...
- CSS3 初步学习
CSS3有一些是与旧版CSS2.1重叠的,有一些是没有浏览器支持的,全学没必要,下面只记录一下有用的. 一.CSS3边框 1.圆角border-radius border-radius:值越大,角越圆 ...
- MySQL 常用命令(持续更新)
停止启动MySQL服务 停止:net stop mysql启动:net start mysql 查看正在运行的线程 SHOW PROCESSLIST SHOW FULL PROCESSLIST 杀死线 ...
- curl 发送get post请求
function getAction($url=''){ // curl 请求一共分四步,初始化,设置属性,执行并获取结果,释放句柄 // 一.初始化 $curl = curl_init(); // ...
- 【EF学习笔记10】----------主从表级联操作
主从表 级联新增 Console.WriteLine("=========主从表 级联新增=========="); using (var db = new Entities()) ...
- 为什么 1KB = 1024Byte???群里讨论。
- webForm中dropDownList的一些用法
DropDownList 控件用于创建下拉列表. DropDownList 控件中的每个可选项都是由 ListItem 元素定义的! 该控件支持数据绑定! DropDownList1.DataSour ...
- objective c, protocol
OC中协议类似于java中的接口,在多个类具有类似的方法时可以将这些方法定义到protocol中,然后各个类分别实现protocol中的各个方法. 例:有两个类Square和Circle, 定义一个p ...
- delphi模拟按键精灵自动控制PDF页面自动扩边的源代码
需要的环境:Adobe Acrobat 7.0 Professional 和 Quite Imposing Plus 1.5d Acrobat plugin (qi160.exe) 程序界面: ...