http://www.lydsy.com/JudgeOnline/problem.php?id=3053 本来是1a的QAQ.... 没看到有多组数据啊.....斯巴达!!!!!!!!!!!!!!!!! 本题裸的kdtree,比上一题还要简单...................................... 对于当前点,判断进入左或右子树,然后看答案是否能过分割线..如果能,进入右或左子树.........并且如果答案个数小于k,也要进入.. 然后就浪吧........... #inc…
赤果果的kdTree. 学习传送门:http://www.cnblogs.com/v-July-v/archive/2012/11/20/3125419.html 其实就是二叉树的变形 #include<bits/stdc++.h> using namespace std; ,K = ; #define squ(x) ((x)*(x)) int k,n,idx; struct Point { int x[K]; bool operator <(const Point& rhs)…
http://www.lydsy.com/JudgeOnline/problem.php?id=3668 这题很简单.............. 枚举每一位然后累计即可.. QAQ,第一次以为能1A,但是wa了..噗,对拍才发现,自己有个地方打残了.. 还是得对拍啊.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream&g…
http://www.lydsy.com/JudgeOnline/problem.php?id=3223 默默的.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue> #include <set> #in…
http://www.lydsy.com/JudgeOnline/problem.php?id=1602 一开始以为直接暴力最短路,但是n<=1000, q<=1000可能会tle. 显然我没有看到树的性质,树边只有n-1,且一个点一定能到达另一个点 所以我们求出lca,然后记录从根到每个点的距离,然后答案就是d[u]+d[v]-2*d[lca(u, v)] 然后blabla就出来了 #include <cstdio> #include <cstring> #inclu…
http://www.lydsy.com/JudgeOnline/problem.php?id=1601 很水的题,但是一开始我看成最短路了T_T 果断错. 我们想,要求连通,对,连通!连通的价值最小!当然是生成树!最小生成树! 边的还好做,但是这题有点,怎么办呢? 因为点在图中也起到连通作用,我们加个附加源,向每个点连边,价值为对应点权. ! 然后就ok了.. #include <cstdio> #include <cstring> #include <cmath>…
http://www.lydsy.com/JudgeOnline/problem.php?id=1600 说好的今天开始刷水.. 本题一开始我以为是排列组合,但是自己弱想不出来,只想到了如果四边有一条边大于或等于第三边,那么这个四边形构造不出来. 即 a>=b+c+d时,不存在四边形 那么存在的情况就是a<b+c+d 得到 a<a+b+c+d 因为a<2a,a<b+c+d 所以a<(a+b+c+d)/2=n/2 那么我们就可以dp了. 只要找所有满足的边满足比长度的一半…
http://www.lydsy.com/JudgeOnline/problem.php?id=1503 这题没有看题解就1a了-好开心,, 其实后面去看题解发现他们的都很麻烦,其实有种很简单的做法: 题目要求全体人+和-,那么我们只用开变量m1来累计即可,由于splay的特殊性-我们将下界加上这个变量m1然后插入到splay中作为根,然后把左边的全部去掉即可---啦啦啦-.-然后出答案时,减去这个变量m1- 还有我们在插入一个新的工资时,要加上这个变量m1插入,要不然会被直接刷掉.... #i…
http://www.lydsy.com/JudgeOnline/problem.php?id=1269 这题RE2次啊,好不爽啊,我一直以为是splay的问题,其实是数组开小了......(我老犯这种低级错啊喂.. 和1507一样是模板题,指针版的速度依旧不行,,,,太慢了. #include <string> #include <cstdio> #include <algorithm> using namespace std; char strI[1024*1024…
题目 传送门:QWQ 分析 k短路,Astar.估价函数是终点向外跑的最短路. 显然不是正解qwq. 代码 // By noble_ // Astar algorithm // #include <bits/stdc++.h> #include <cstdio> #include <algorithm> #include <cstring> #include <queue> #include <vector> using namesp…
题目 传送门:QWQ 分析 发现我们关心的不是棋子的位置,我们只关心棋子数量就ok. 首先每行每列最多两个棋子.这是显然的. 然后我觉得本题最难的部分就是对行进行讨论,蒟蒻我一直被限制在了对格点讨论.... $dp[i][j][k] $放了前$i$行,有$j$列有1个棋子,有$k$列有2个棋子.转移就很显然了. 代码 #include <bits/stdc++.h> typedef long long ll; ;; ll dp[maxn][maxn][maxn]; //dp[i][j][k]…
http://www.lydsy.com/JudgeOnline/problem.php?id=1034 弱的比弱的强就用,强的比强的强就用: 否则弱的和强的比. 输的情况就是2n-ans(b,a),因为总分是2n #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm>…
http://www.lydsy.com/JudgeOnline/problem.php?id=1011 题意:$f[i] = \sum_{j=1}^{i-1} \frac{M[i]M[j]}{i-j}$,求$1<=n<=10^5$的所有$f[i]$ orz 神题啊... 第一次做这种近似的题orz 首先n^2肯定是不可做的.. 然后看了题解.. 好神 首先得到$f[i]$表示第$i$个的能量, $g[i]$为题目给的$A*i$ $$f[i]=M_i \times \sum_{j=1}^{g[…
http://www.lydsy.com/JudgeOnline/problem.php?id=1631 看到m<=100000果断用dij(可是好像dij比spfa还慢了在这里?)//upd:那是因为你写的根本不是dij,,233 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <…
http://www.lydsy.com/JudgeOnline/problem.php?id=1685 由于每个小的都能整除大的,那么我们在取完大的以后(不超过c)后,再取一个最小的数来补充,可以证明这是最优的. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm>…
题目 传送门:QWQ 分析 (sb如我写了发不知道什么东西在洛谷上竟然水了84分 嗯咳 设$ i $为双重回文的中心 如果$ j~i $ 可以被算作答案,只有满足如下两式: $ p[j]+j \geq i $ $ 2*(i-j) \leq p[j] $ 计算时我们先做一次马拉车,然后按照 $ p[j]+j \geq i $排序,保证它的单调,接着把满足$ 2*(i-j) \leq p[j] $扔进set里询问. 代码 #include <bits/stdc++.h> using namespa…
题目 传送门:QWQ 分析 在下面维护一个凸壳 好久没写博客了...... 代码 #include <bits/stdc++.h> using namespace std; ; ,INF=1e10; struct Line{ double a,b;int n; }l[maxn]; Line st[maxn];; bool cmp(Line a,Line b){ if(fabs(a.a-b.a)<eps)return a.b<b.b; return a.a<b.a; } boo…
http://www.lydsy.com/JudgeOnline/problem.php?id=1632 我简直是个sb... ... bfs都不会写.. 算方案还用2个bfs! 都不会整合到一个! 然后赤裸裸的wa了. 然后对拍... 噗 果然错的地方很... .. 然后貌似自己想改bfs,只需一个就行了.. 而且方案也改对了???? 然后不知哪里写挫了...然后样例过不了了.. 然后无奈看别人题解了... QAQ 噗,方案和我想的一样,但是...............我忘记了个东西,,标记…
http://www.lydsy.com/JudgeOnline/problem.php?id=2014 这应该是显然的贪心吧,先排序,然后按花费取 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue> using na…
http://www.lydsy.com/JudgeOnline/problem.php?id=2021 噗,自己太弱想不到. 原来是2次背包. 由于只要有一个大于k的高度的,而且这个必须放在最顶,那么我们就可以枚举每一个比k大的放在最顶,其它的都放在下边即可. 还有,注意这是完全背包! #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <i…
http://www.lydsy.com/JudgeOnline/problem.php?id=2015 这种水题真没啥好说的.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue> using namespace s…
http://www.lydsy.com/JudgeOnline/problem.php?id=1680 看不懂英文.. 题意是有n天,第i天生产的费用是c[i],要生产y[i]个产品,可以用当天的也可以用以前的(多生产的).每单位产品保存一天的费用是s.求最小费用 显然贪心,每次查找之前有没有哪一天保存到现在的价值最小,然后比较更新.. #include <cstdio> #include <cstring> #include <cmath> #include <…
http://www.lydsy.com/JudgeOnline/problem.php?id=3296 显然,每群能交流的群是个强联通块 然后求出scc的数量,答案就是scc-1 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <qu…
http://www.lydsy.com/JudgeOnline/problem.php?id=3538 题意不要理解错QAQ,是说当前边(u,v)且u到n的最短距离中包含这条边,那么这条边就不警告. 那么我们反向spfa两次,然后再正向spfa就行了 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #inclu…
http://www.lydsy.com/JudgeOnline/problem.php?id=3300 这个细节太多QAQ 只要将所有的括号'('匹配到下一个')'然后dfs即可 简单吧,,, #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include…
http://www.lydsy.com/JudgeOnline/problem.php?id=3016 之前yy了一个贪心,,,但是错了,,就是枚举前后对应的字符(前面第i个和后面第i个)然后相同答案就+1,否则不操作.. QAQ 然后看了题解...神.. 首先序列肯定是偶数个,然后..一定有n/2个‘(’,和n/2个‘)’ 那么左边的一定都是‘(’,对于每一个‘(’,右边的一定有一个‘)’,所以我们想到差分,当右边多了‘)’,那么就要累计答案+1,维护一个sum,如果是‘(’就+1,‘)’就…
http://www.lydsy.com/JudgeOnline/problem.php?id=2019 spfa裸题.....将飞机场的费用变成负,然后spfa找正环就行了 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue…
[BZOJ2186]沙拉公主的困惑(数论) 题面 BZOJ 题解 考虑答案是啥 先假设\(n=m\) 现在求的就是\(\varphi(m!)\) 但是现在\(n!\)是\(m!\)的若干倍 我们知道 \(gcd(x,y)=gcd(x+ky,y)\) 所以,相当于 每隔\(m!\),答案增长的值都是\(\varphi(m!)\) 所以 我们可以得出 \[ans=\frac{n!}{m!}\varphi(m!)\] 后面的\(\varphi\)可以直接拆开,枚举质因数 \[ans=\frac{n!}…
[BZOJ4822][CQOI2017]老C的任务(扫描线) 题面 BZOJ 洛谷 题解 没有修改操作,都不需要分治了... 直接排序之后扫描线算贡献就好了... 不知道为啥洛谷上过不了... #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<ve…
[BZOJ1484][HNOI2009]通往城堡之路 (贪心) 题面 BZOJ 洛谷 题解 我大概是不会的. 大概是,首先把所有的人全部弄成最低的值,再一次次拔高一个后缀. 其他的全是抄的,百度随便找篇题解好了,谁会做了教我一下. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm…