自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

月阁

在这世界留下点什么

  • 博客(200)
  • 收藏
  • 关注

原创 51nod 1128 正整数分组 V2

二分下答案就好了。#includeusing namespace std;const int MAXN=50050;long long n,k;long long a[MAXN];bool judge(long long limit){ long long sum=1,now=0,i; for(i=1;i<=n;i++) { if(a[i]>limit) ret

2016-11-30 23:14:04 269

原创 51nod 1052 最大M子段和

设 dp[i][j] 表示前i个元素,选取j个区间,且第i个元素必选的情况下的最大字段和。dp[i][j]=max(dp[i-1][j]+a[i],max(dp[k,j-1]+a[i]));0≤k≤i-1空间压缩一下,前缀也dp一下就好了。#includeusing namespace std;const int MAXN=5050;long long a[MAXN],dp

2016-11-30 22:52:54 229

原创 51nod 1201 整数划分

偷懒写了记忆化,没爆栈真的好神奇。。。因为每次操作最大为2*mod,所以数组开int就够了dp[x][y]=(dfs(x-y,y-1)+dfs(x-y,y))%mod;dp[x][y]表示y个不同的数字之和x的种数。#includeusing namespace std;const int mod=1e9+7;int dp[50050][350];int dfs(int

2016-11-30 22:14:03 180

原创 51nod 1029 大数除法

java大法过的。。。。import java.util.*;import java.math.*;public class acm { public static void main(String[] args){ BigInteger a,b,c,d; Scanner input=new Scanner(System.in); while(input.hasNextB

2016-11-29 22:48:55 299

原创 51nod 1028 大数乘法 V2

标准做法是FFT,偷懒用了java。。。import java.util.*;import java.math.*;public class acm { public static void main(String[] args){ BigInteger a,b; Scanner input=new Scanner(System.in); while(input.hasN

2016-11-29 22:41:15 236

原创 51nod 1677 treecnt

可以计算出每条边出现的次数,其总和就是答案。对于任意一条边,若其左端有x个节点,右端有y个节点。那么这条边的出现次数为C(n,k)-C(x,k)-C(y,k)计算组合数时,预处理阶乘和逆元。#includeusing namespace std;const long long mod=1e9+7;const int MAXN=100100;long long fac[

2016-11-29 20:39:46 342

原创 51nod 1534 棋子游戏

对于v来说,一开始尽可能的斜着移动,直到遇到边界,或者被p拦截。一旦被p成功拦截那么v必输。所以问题就变成了p能否成功拦截v。即v移动的过程中,是否存在一个点,p也刚好,或提前到达这个点。所以有两种情况:1.v移动到xv=xp或yv=yp的时候,p成功或提前拦截。2.v移动到边界后,进行水平或直线移动,直到xv=xp或yv=yp的时候,p提前或成功拦截。可以看出,拦截点都在

2016-11-29 19:05:26 589

转载 51nod 1423 最大二“货”

用单调栈维护区间最大值。#includeusing namespace std;const int MAXN=100100;int stk[MAXN],a[MAXN];int main(){ int n,ans,cnt,i; while(~scanf("%d",&n)) { for(i=1;i<=n;i++) scanf("%d",&a[i]); ans=0;

2016-11-24 21:53:40 340

原创 51nod 1020 逆序排列

dp+内存压缩+前缀和+离线处理dp[i][j] 表示 n=i,k=j 时的答案。pre[i][j] 表示在 dp[i][j] 的前缀和。转移方程:dp[i][j]=pre[i-1][j]-(j-i>=0?pre[i-1][j-i]:0)#includeusing namespace std;const long long mod=1e9+7;long long d

2016-11-24 20:47:42 213

原创 51nod 1040 最大公约数之和

#includeusing namespace std;long long oula(long long n){ long long rea=n; for(long long i=2; i*i<=n; i++) { if(n%i==0) { rea=rea-rea/i; while(n%i==0) n/=i; } } if(n>1) rea=r

2016-11-24 18:44:46 172

原创 51nod 1624 取余最长路

相当于分成三段,第一段为第一行走的路线总和,第二段为第二行走的路线总和,第三段为第三行走的路线总和。可以枚举第一个分割点,二分查找第二个分割点。#includeusing namespace std;const int MAXN=100100;long long mz[5][MAXN],pre[5][MAXN];set st;set ::iterator it;int main

2016-11-24 17:06:14 175

原创 51nod 1714 B君的游戏

打表。。。#includeusing namespace std;long long dp[65]={ 0, 1, 2, 4, 8, 16, 32, 64, 128, 255, 256, 512, 1024, 2048, 3855, 4096, 8192, 13107, 16384, 21845, 27306, 32768, 38506, 65536, 71576, 9

2016-11-24 15:43:09 353

转载 51nod 1686 第K大区间

二分答案,求解时,采用了容斥。#includeusing namespace std;const int MAXN=100100;int a[MAXN],b[MAXN];long long n;long long mul(long long x){ if(x<=0) return 0; return x*(x-1)/2;}long long cal(int x)

2016-11-24 01:38:19 306

转载 51nod 1093 骆驼和香蕉

#includeusing namespace std;int main(){ double n,k,ans,flag,tag; while(scanf("%lf%lf",&n,&k)!=EOF) { flag=1; tag=0; while(n-k/flag>=0) { n-=k/flag; flag+=2; tag++; } ans=ta

2016-11-23 21:04:30 138

原创 51nod 1682 中位数计数

N^2水过。。#includeusing namespace std;const int MAXN=8080;int num[MAXN],ans[MAXN],arr[MAXN],sum[MAXN<<1];int main(){ int n,i,j; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) scanf("%d",

2016-11-23 03:10:29 245

原创 1478 括号序列的最长合法子段

感觉自己宛如一个智障。。。维护一个栈,dp保证相邻的合法括号能够相连接,就好了。#includeusing namespace std;const int MAXN=1001000;char s[MAXN];int dp[MAXN];stack stk;int main(){ int len,i,ans,sum,tmp; while(scanf("%s",&s)!=E

2016-11-23 02:23:36 295

原创 51nod 1672 区间交

枚举区间交的左端点,multiset维护右端点。#includeusing namespace std;const int MAXN=100100;struct segment{ int lef,rig;}seg[MAXN];bool cmp(segment s1,segment s2){ if(s1.lef!=s2.lef) return s1.lef<s2.le

2016-11-21 02:30:40 211

原创 51nod 1464 半回文

一开始想到后缀数组,然后发现好难处理对称的。参考了 f_zyj 的代码,发现用字典树做,对称采用了DP优化。这个DP优化好神奇啊。。。。打完后想想,好像后缀数组也能做。。。。#includeusing namespace std;const int MAXN=200200;char s[MAXN];int cnt,n,k,vis[5050];bool dp[5050][5050

2016-11-21 01:29:39 334

原创 51nod 1388 六边形平面

首先很容易得出,最多3种颜色,就能将任意六边形图进行染色。1种颜色和2种颜色情况很容易求解。对于3种颜色,需要满足一下之一的条件:1.存在3个六边形共顶点。2.存在奇数环。奇数环可以直接用dfs求解。#include using namespace std;int go[6][2]={{0,1},{0,-1},{1,0},{-1,0},{1,-1},{-1,1}};ch

2016-11-20 23:13:50 248

原创 51nod 1351 吃点心

O(n)的算法,数据量居然只有50。。。对于选取的若干盒子,有两种情况是符合条件的1.这些盒子的low和 ≥ x2.c - 其他盒子的high和 ≥ x分别进行计算,求较小值即可。#include using namespace std;const int MAXN=55;struct box{ int low,high;}arr[MAXN];bool cm

2016-11-20 21:30:59 250

原创 51nod 1107 斜率小于0的连线数量

将点按横坐标x排序,然后提取纵坐标y,求逆序数对即可。#include using namespace std;const int MAXN=50050;struct node{ int x,y;}nod[MAXN];bool cmp(node n1,node n2){ if(n1.x!=n2.x) return n1.x<n2.x; return n1.y<n2

2016-11-20 20:29:03 218

原创 51nod 1460 连接小岛

贪心+二分。将桥的合法范围进行排序,二分查找对应的桥。#includeusing namespace std;const int MAXN=200200;struct seg{ long long mn,mx;}bdg[MAXN];bool cmp(seg s1,seg s2){ if(s1.mx!=s2.mx) return s1.mx<s2.mx; else

2016-11-20 02:13:53 231

原创 51nod 1484 猜数游戏

很容易将题意转化为区间交与区间并的问题。由于题目只要求出1个合法的值,所以取巧用了一些方法。先判断ans=1的情况下,所有的区间交是否为空,如果不为空,求出区间交。这个很容易求出。对于ans=0的情况,将所有点对离散。为了方便,用了map进行离散操作。mp[not_lef]-=inf;mp[not_rig+1]+=inf这样,但凡值为 -inf 的区间,都为非法区间。将之前

2016-11-20 01:29:23 247

转载 51nod 1112 KGold

宛如自己是一个智障。。。打错1个字母,调了一天。。。。二分找出第10000次超越发生的时间,然后N*N时间内计算答案。由于许多都会被continue,所以进行直线交的计算次数只有1W,不会超时。#includeusing namespace std;const int MAXN=10010;int n;struct preson{ int index,ordinal,m,s

2016-11-19 23:05:30 276

转载 51nod 1335 子序列翻转

#includeusing namespace std;char s[2510];int letter[30],y[2510];int main(){ int T,i,j,cnt,len,x,ansy,ysum,flag; scanf("%d",&T); while(T--) { scanf("%s",&s); len=strlen(s); memset(lett

2016-11-19 00:31:03 270

转载 51nod 1473 等幂映射

#includeusing namespace std;const int MAXN=210;long long gcd(long long a,long long b){ return a%b?gcd(b,a%b):b;}long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}long long f[

2016-11-18 21:28:01 285

原创 51nod 1076 2条不相交的路径

江老板说tarjan模板题,然后就抄了板子,其实并不懂为什么。。。。#includeusing namespace std;const int N=26000;const int M=50050;int e[M][2],cut[M],g[N],v[M<<1],nxt[M<<1],ed;int f[N],dfn[N],low[N],num,cnt,from[N];void add(

2016-11-18 00:21:48 286

原创 51nod 1674 区间的价值 V2

#include using namespace std;const long long mod=1000000007;long long a[100100],dif[100100][35],bef[2][35],diforder[35];int main(){ long long n,i,j,ans,andsum,orsum; while(cin>>n) { for(i=

2016-11-17 22:19:58 212

原创 51nod 1400 序列分解

只有40长度,dfs一下就好。由于剪枝,时间复杂度O(2^20)。#includeint a[44],b[44],arr[44],n,flag;void dfs(int deep,int alen,int blen){ if(deep==n||flag) { flag=1; return; } if(alen==blen) { a[alen+1]=arr[d

2016-11-17 21:19:24 243

原创 51nod 1655 染色问题

迷之规律?#includeint main(){ int T,n,i,j; scanf("%d",&T); while(T--) { scanf("%d",&n); printf("%d\n",n); if((n&1)==0) { printf("No solution\n"); continue; } for(i=1;i<=n;i++)

2016-11-17 20:47:55 216

原创 51nod 1109 01组成的N的倍数

BFS#includeusing namespace std;const int MAXN=1000100;int dis[MAXN],pre[MAXN];char ans[MAXN];int main(){ int n,i,now,cnt,nxt; while(scanf("%d",&n)!=EOF) { memset(dis,-1,sizeof(dis));

2016-11-17 15:30:46 257

原创 51nod 1153 选择子序列

#includeusing namespace std;const int MAXN=50050;int a[MAXN],dis[MAXN];vector g[MAXN];int dfs(int x){ if(dis[x]!=-1) return dis[x]; int i,ret=1; for(i=0;i<g[x].size();i++) ret=max(ret,

2016-11-17 01:00:04 348

翻译 51nod 1607 卷积和

分类是数位DP,但自己数位DP想不出来。参照一位大佬的代码,然后慢慢看懂自己加注释。。。。大佬的传送门:http://blog.csdn.net/fsss_7/article/details/52085170#includeusing namespace std;const long long mod=1e9+7;int digit[25];long long pow10[25]

2016-11-16 23:36:34 532

原创 51nod 1243 排船的问题

这么一道简单题,居然因为2次看错题目被卡住了。。。二分一下就好。#includeusing namespace std;const int MAXN=50050;long long n,m,x;long long p[MAXN];bool judge(long long limit){ long long bef=x,i,dis; for(i=0;i<n;i++) {

2016-11-16 01:16:11 275

原创 51nod 1337 翻转游戏

从后向前扫即可。情况有点多,不要落下就行。#includeusing namespace std;char mz[55][55],str[55];int main(){ int T,i,j,n,m,ans,open,close; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); for(i=1;i<=n;i++)

2016-11-15 15:47:01 270

原创 51nod 1420 数袋鼠好有趣

贪心+二分能装进大袋鼠的小袋鼠,肯定是最小的那几个。所以二分枚举小袋鼠的数量即可。#includeusing namespace std;const int MAXN=500500;int n,a[MAXN];bool judge(int x){ for(int i=0,j=n-x;i<x;i++,j++) { if(a[i]+a[i]>a[j]) retu

2016-11-15 01:32:48 234

原创 51nod 1350 斐波那契表示

,我们简单列下前几组数据x     1  2  3  4  5  6  7  8  9  10  11  12  13     *  *  *     *       *                *F(x)   1  1  1  2  1  2  2  1  2   2   2   3   1  G(x)   1  2  3     6       11

2016-11-15 00:22:59 601

原创 51nod 1422 沙拉酱前缀

记录所有操作以及操作结束后的数列长度。对于每个询问,二分查找对应的操作。如果查找到的操作种类为2,则继续向前二分查找,直到查找到的操作种类为1为止。时间复杂度O(N*log(N)*log(N))#includeusing namespace std;const int MAXN=100100;long long op[MAXN],pos[MAXN],l[MAXN],c[MAXN],

2016-11-14 21:12:49 247

转载 51nod 1412 AVL树的种类

#includeusing namespace std;const long long mod=1e9+7;long long dp[20][2020]; int main(){ long long n,i,j,k,ans; memset(dp,0,sizeof(dp)); dp[0][0]=dp[1][1]=1; for(i=2;i<16;i++) { for(j=

2016-11-14 20:42:54 213

原创 51nod 1434 区间LCM

#includeusing namespace std;const int MAXN=1000100;int fac[MAXN],pri[MAXN];int main(){int psum,ans,i,j,T,n;psum=0;for(i=2;i{if(!fac[i]){pri[psum++]=i;for(j=i+i;j

2016-11-10 23:04:49 395

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除