不知道是啥
沙茶
这个作者很懒,什么都没留下…
展开
-
[noip2002pj] 级数求和
题目链接题解:写几道水题题解……#include<iostream>using namespace std;int main(){ double S = 0; int k,i = 1; cin>>k; while(S<=k); { S += (1.0)/i; i++; } cout<<i<<endl; ret原创 2016-08-16 23:24:37 · 325 阅读 · 0 评论 -
[hdu4547] CD操作
题目链接题目大意:给一棵n(n<=100000)个节点的树,有两种移动方式:1.到父节点 2.到子树中任意一个节点 m次询问,求两个节点之间的最小次数题解:需要hash……这里直接用的map。然后就是根据lca大力分类讨论了#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <原创 2017-01-01 10:19:56 · 319 阅读 · 0 评论 -
[noip2012tg] 同余方程
题目链接题解:丧病的模板题#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int a,b,d,x,y;void exgcd(int a,int b,int &d,int &x,int &y){ if (!b) {d=a;x=1;y=0;} else {exgcd(b,a原创 2016-11-12 16:17:39 · 225 阅读 · 0 评论 -
[luogu1284] 三角形牧场
题目链接题解:随机化………………#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>using namespace std;int n,a[41],ans=-1;void wash()//随机洗木板顺序{ for(int i=1;i<=n;i++) { int t=r原创 2016-11-12 15:10:00 · 325 阅读 · 0 评论 -
[noip2008tg] 火柴棒等式
题目链接题解:打个表……#include <iostream>#include<cstring>#include<cstdio>using namespace std;int num;int ss[10]={6,2,5,5,4,5,6,3,7,6};int find(int x){ num=0; while(x/10>0) { num+=ss[x原创 2016-11-12 15:04:25 · 378 阅读 · 0 评论 -
[noip2005pj] 校门外的树
题目链接题解:非常奇怪的用并查集维护区间的做法#include <iostream>#include <cstdio>using namespace std;int r[100000],f[100000];int find(int x){ return f[x]==x?x:f[x]=find(f[x]);}void uniom(int u,int p){ int x=fi原创 2016-11-12 14:20:26 · 480 阅读 · 0 评论 -
[noip2013tg] 火柴排队
题目链接题解:看到题目,很容易想到,当两序列中最大对最大,次大对次大时,结果最小。结合题目给出的要求,很容易想到,如果把序列A用冒泡排序变成序列B,交换的次数就是答案。用O(n^2)模拟一下,就能拿60了,再结合一下冒泡排序交换次数等于逆序对数这一性质,可以用O(nlogn)求出排名数组的逆序对数这里写代码片原创 2016-11-11 19:26:38 · 156 阅读 · 0 评论 -
[codevs3500] 快速幂入门
题目链接题解:快速幂模板#include <iostream>#include <cstdio>using namespace std;#define LL long longLL a,b,c;LL fast_pow(LL a,LL p){ LL ans=1; for(;p;p>>=1,a=(a*a)%c) if(p&1) ans=(an原创 2016-08-25 23:27:02 · 192 阅读 · 0 评论 -
[noip2013tg] 花匠
[题目链接](http://www.luogu.org/problem/show?pid=2832题解:我们对这道题目进行分析,发现这道题目要求的实际上是最长的波动子序列。 对于一段单调的序列(注意,这里的单调指的是单调不增或者单调不减),我们最多从中取两个点。 所以,如果我们取整个序列的拐点的话,能够得到最优方案。#include <iostream>#include <cstdio>#i原创 2016-08-26 23:04:47 · 380 阅读 · 0 评论 -
[vijos1571] 笨笨的导弹攻击
题目链接题解:和noip2013花匠很像,记录下奇偶即可#include <iostream>#include <cstdio>using namespace std;int n,tot,flag;//1上升,2下降int a[100005];inline void init(){ cin>>n; for(int i=1;i<=n;i++) scanf("%d",原创 2016-08-26 23:12:55 · 440 阅读 · 0 评论 -
[Usaco07Jan&luogu2880] Balanced Lineup
题目链接题解:rmq#include <cstdio>#include <cmath>#include <iostream>using namespace std;#define pow2(x) (1<<(x))const int M=50005;int n,T,x,y;int a[M],Fmin[M][25],Fmax[M][25];void max_rmq(){ for原创 2016-09-25 17:42:36 · 173 阅读 · 0 评论 -
[bzoj2456] mode
题目链接 题解:内存限制1M 只能开4个int。用神奇(玄学)的抵消思想,因为找的数出现大于n/2次,所以它可以抵消掉其他所有数字#include <cstdio>using namespace std;int n,now,tot,x; int main(){ scanf("%d",&n); while(n--) { scanf("%d",&x);原创 2016-08-10 20:26:47 · 212 阅读 · 0 评论 -
[noip2013tg] 转圈游戏
题目链接题解:手动模拟一下就行#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#define ll long longusing namespace std;ll n,m,k,x,ans;ll fastpow(ll a,ll p) { ll ans=1;a%=n; for原创 2016-11-10 15:39:31 · 199 阅读 · 0 评论 -
[noip2007pj] 纪念品分组
题目链接题解:模拟#include<iostream> #include<algorithm> using namespace std; int a[30001];int main () { int n,m; cin>>n>>m; for(int i=1;i<=m;i++) cin>>a[i]; sort(a+1,a+m+1);原创 2016-11-05 09:42:28 · 211 阅读 · 0 评论 -
[codevs3145] 汉诺塔游戏
题目链接题解:……#include <iostream>#include <cstdio>using namespace std;int a[100];void move(int n,int a,int b,int c){ if(n==1) printf("%d from %c to %c\n", n, a, c); else { move(n-1,原创 2016-11-05 09:19:15 · 199 阅读 · 0 评论 -
[noip2006pj] 明明的随机数
题目链接题解:随手写个桶排序#include<iostream>using namespace std;int n,sum,x;int a[1001];int main(){ cin>>n; for(i=1;i<=n;i++){ cin>>x; a[x]=1;//去重 } for(i=1;i<=1000;i++) su原创 2016-08-16 23:48:10 · 258 阅读 · 0 评论 -
[noip2005pj] 校门外的树
题目链接题解:线性扫描#include <iostream>using namespace std;int a,b;int check[100000];int main(){ int n,m; int s=0; cin>>n>>m; for(int i=1;i<=m;i++) { cin>>a>>b; for(int原创 2016-08-16 23:35:06 · 178 阅读 · 0 评论 -
[noip2001pj] 数的计算
题目链接题解:当n为1时,1满足题意 当n为2时,2,12满足题意 当n为3时,3,13满足题意 当n为4时,4,14,24,124满足题意 当n为5时,5,15,25,125满足题意 当n为6时,6,16,26,36,126,136满足题意 f[n]=f[1]+f[2]……+f[n/2]+1 递归来写简洁一些include <iostream>using namespace std原创 2016-08-16 23:19:50 · 243 阅读 · 0 评论 -
[uva820] Internet Bandwidth
题目链接题目大意:最大流模板题解:ISAP#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define INF 0x7fffffffconst int M=405;using namespace std;int kase,n,m,se,ed,t;int head[M],last[M]原创 2017-01-01 10:39:12 · 342 阅读 · 0 评论