摘要: #include<queue>#include<utility>#include<iostream> using namespace std;struct number{ int x,y; number(int xx,int yy){ x=xx,y=yy; } bool operator < (co 阅读全文
posted @ 2017-01-17 18:26 despair_ghost 阅读(338) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1116 题意:判断n个单词是否可以相连成一条链或一个环,两个单词可以相连的条件是 前一个单词的最后一个字母和后一个单词的第一个字母一样。 分析前提:有(无)向图的欧拉路径判断均是基于连通图 欧拉路径判断: 1、一个 阅读全文
posted @ 2017-01-17 17:28 despair_ghost 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 没用过Leetcode刷题,只能按照自己的想法随便写写了 思路:1.第一位数有9种(除了0)可能,第二位数有9种(除了第一位)可能,第三位数有8种(除了前两位)可能,以此类推...9*8*7*...(9-i+2)种; 2.当n>=10时,后面必定有重复数字,不能算进去,所以和n=10的种数相同 阅读全文
posted @ 2017-01-17 12:16 despair_ghost 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 第一步,首先通过给的第一,第二,第三组数据,可以发现一个规律,那就是右边界肯定要算进去,比如[1,10]那么10一定要算进去。 即得最后结果中或值最大的两个数中的第一个数x; 为什么呢?我们可以稍微证明一下:假设右边界为r,考虑r-1.第一种情况,如果r-1的二进制位数比r少一位,那么无疑应该选r; 阅读全文
posted @ 2017-01-17 11:12 despair_ghost 阅读(259) 评论(0) 推荐(0) 编辑
摘要: 交通规划 问题描述 G国国王来中国参观后,被中国的高速铁路深深的震撼,决定为自己的国家也建设一个高速铁路系统。 建设高速铁路投入非常大,为了节约建设成本,G国国王决定不新建铁路,而是将已有的铁路改造成高速铁路。现在,请你为G国国王提供一个方案,将现有的一部分铁路改造成高速铁路,使得任何两个城市间都可 阅读全文
posted @ 2017-01-17 11:09 despair_ghost 阅读(703) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std; long long mpow(long long a,long long b) { long long ans=1; if(b==0) return 1; while(b){ ans=ans*a; b--; } return ans; } l... 阅读全文
posted @ 2017-01-17 11:07 despair_ghost 阅读(186) 评论(0) 推荐(0) 编辑
摘要: #include #include int main() { //freopen("orz.txt","w",stdout); int i,j,n,m,x,y; while(scanf("%d%d",&n,&m)!=EOF) { int c[n][m]; int d[n*m]; memset(c,0,sizeof(0... 阅读全文
posted @ 2017-01-17 11:06 despair_ghost 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 问题描述 《炉石传说:魔兽英雄传》(Hearthstone: Heroes of Warcraft,简称炉石传说)是暴雪娱乐开发的一款集换式卡牌游戏(如下图所示)。游戏在一个战斗棋盘上进行,由两名玩家轮流进行操作,本题所使用的炉石传说游戏的简化规则如下: * 玩家会控制一些角色,每个角色有自己的生命 阅读全文
posted @ 2017-01-17 11:05 despair_ghost 阅读(1350) 评论(0) 推荐(0) 编辑
摘要: 解法一:数论筛法+前缀和 解法二:数论筛法+树状数组 阅读全文
posted @ 2017-01-17 11:04 despair_ghost 阅读(270) 评论(0) 推荐(0) 编辑
摘要: 原题链接,点击此处 欧拉函数:φ(N)表示对一个正整数N,欧拉函数是小于N且与N互质的数的个数 通式:φ(x) = x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn) 其中p1, p2……pn为x的所有质因数,x是不为0的整数。 注意:将n分解为最简质因数,每种 阅读全文
posted @ 2017-01-17 11:03 despair_ghost 阅读(246) 评论(0) 推荐(0) 编辑
摘要: #include #define N 10007 #define maxn 1000005 int dp[maxn]; int main() { dp[1]=1,dp[2]=2,dp[3]=4; for(int i=4;i<maxn;i++) dp[i]=dp[i-1]%N+dp[i-2]%N+dp[i-3]%N; int n; while(sca... 阅读全文
posted @ 2017-01-17 11:01 despair_ghost 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 解法一:简单搜索肯定TLE,只是单纯的想写一发搜索练练手 解法2:动态规划 阅读全文
posted @ 2017-01-17 11:00 despair_ghost 阅读(126) 评论(0) 推荐(0) 编辑
摘要: #include #define maxn 1005 int c[maxn][maxn]; int gcd(int a,int b){ return b==0?a:gcd(b,a%b); } int main() { int n,m,ans,tmp; while(scanf("%d%d",&n,&m)!=EOF){ ans=0; for(... 阅读全文
posted @ 2017-01-17 10:57 despair_ghost 阅读(87) 评论(0) 推荐(0) 编辑
摘要: 解法1:TLE 解法2:AC 阅读全文
posted @ 2017-01-17 10:56 despair_ghost 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 对于一排n个正方形,有f(n)种方案达成目标,若第n个块是白色,则有f(n-1)种方案,若第n个块是黑色,则第n-1个块必为白色,那么有f(n-2)+n-2种方案。 则f(n)=f(n-1)+f(n-2)+n-2 。 写成矩阵形式: (http://img.blog.csdn.net/2016101 阅读全文
posted @ 2017-01-17 10:52 despair_ghost 阅读(135) 评论(0) 推荐(0) 编辑
摘要: #include typedef long long ll; const ll mod=10007; ll feima(ll a,ll b) { ll c=1; while(b) { if(b&1) c=c*a%mod; a=a*a%mod; b=b>>1; } return c; ... 阅读全文
posted @ 2017-01-17 10:49 despair_ghost 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 思路: 因为T<=10000,所以税前极限金额肯定不超过1000000(设个比较大的数字就行),然后逐一计算即可。 阅读全文
posted @ 2017-01-17 10:28 despair_ghost 阅读(1587) 评论(0) 推荐(0) 编辑