恒邪

04 2014 档案

hdu acm 2082 找单词
摘要:找单词Time Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3722Accepted Submission(s): 2663Problem Descrip... 阅读全文

posted @ 2014-04-30 19:13 恒邪 阅读(487) 评论(0) 推荐(0)

hdu acm 1028 数字拆分Ignatius and the Princess III
摘要:Ignatius and the Princess IIITime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11810Accepted Submiss... 阅读全文

posted @ 2014-04-30 16:10 恒邪 阅读(306) 评论(0) 推荐(0)

整理,模板
摘要:组合数学、-排列组合数----sum求sum=sum*(m--)/i;int c(int n,int m)//n下标,m上标{ int sum=1; for(int i=1;in-m) m=n-m; int temp=n; for(int i=1;i1) { up[j]/=temp; d... 阅读全文

posted @ 2014-04-30 12:06 恒邪 阅读(212) 评论(0) 推荐(0)

组合数学笔记
摘要:组合数学、-排列组合数----sum求sum=sum*(m--)/i;----二维数组递推(打表)---原始公式(单个)数字太大,用分子分母约分-全排列模板-----生成全排列函数prev_permutation和next_permutation区别http://www.cnblogs.com/zh... 阅读全文

posted @ 2014-04-29 10:27 恒邪 阅读(192) 评论(0) 推荐(0)

[ACM] poj 2456 Aggressive cows (二分查找)
摘要:Aggressive cowsTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 5436Accepted: 2720DescriptionFarmer John has built a new long barn, with N (2 #include #include using namespace std;const int maxn=100002;const int inf=0x7fffffff;int x[maxn];int n,c;bool ok(int m){ int last=0; for(int i=1... 阅读全文

posted @ 2014-04-28 20:47 恒邪 阅读(202) 评论(0) 推荐(0)

[ACM] poj 1064 Cable master (二分查找)
摘要:Cable masterTime Limit: 1000MSMemory Limit: 10000KTotal Submissions: 21071Accepted: 4542DescriptionInhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee has volunteered and has promised to organize the most honest contest ever. It was decided to con 阅读全文

posted @ 2014-04-28 19:31 恒邪 阅读(179) 评论(0) 推荐(0)

[ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)
摘要:Constructing Roads In JGShining's KingdomTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 14635Accepted Submission(s): 4158Problem DescriptionJGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two 阅读全文

posted @ 2014-04-28 16:36 恒邪 阅读(162) 评论(0) 推荐(0)

[2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)
摘要:Pick applesTime Limit: 1000MS Memory limit: 165536K题目描述Once ago, there is a mystery yard which only produces three kinds of apples. The number of each kind is infinite. A girl carrying a big bag comes into the yard. She is so surprised because she has never seen so many apples before. Each kind of a 阅读全文

posted @ 2014-04-28 14:13 恒邪 阅读(215) 评论(0) 推荐(0)

Mine Number(搜索,暴力) ACM省赛第三届 G
摘要:Mine NumberTime Limit: 1000ms Memory limit: 65536K有疑问?点这里^_^题目描述Every one once played the game called Mine Sweeping, here I change the rule. You are g... 阅读全文

posted @ 2014-04-28 11:07 恒邪 阅读(275) 评论(0) 推荐(0)

sscanf函数用法详解
摘要:sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: Int sscanf( string str, string fmt, mixed var1, mixed var2 ... ); int scanf( const char *format [,argument]... ); 说明: sscanf与scanf类似,都是用于输入的,只是后者以屏幕(stdin)为输入源,前者以固定字符串为输入源。 其中的format可以是一个或多个 {%[*] [width] [{h | l | I64 | L}]type | ' ' | '\t' | & 阅读全文

posted @ 2014-04-27 19:30 恒邪 阅读(190) 评论(0) 推荐(0)

[数据结构] 迷宫问题(栈和队列,深搜和广搜)
摘要:代码:#include #include #include #include #include using namespace std;int dx[4]={0,-1,1,0};//方向int dy[4]={-1,0,0,1};bool vis[6][6];int total=0;//多少可到达路径int sx=1,sy=1;//入口出口坐标int ex=4,ey=4;int num[10][10];//广搜时记录到达当前点的最少步数struct P{ int x,y;}point[40];//用来记录可到达路径struct PP{ int fx,fy;}path[10][10];... 阅读全文

posted @ 2014-04-26 12:55 恒邪 阅读(421) 评论(0) 推荐(0)

[数据结构] N皇后问题
摘要:代码:#include #include #include using namespace std;const int N=100;int c[N];//皇后第i行放在第几列上int n,total;int cc;//方法数void dfs(int cur){ if(cur>n) { cout>n; if(n<=0) { cout<<"输入不合法,程序退出!"<<endl; break; } cc=1; total=0; dfs(1); ... 阅读全文

posted @ 2014-04-26 12:52 恒邪 阅读(315) 评论(0) 推荐(0)

[2011山东ACM省赛] Sequence (动态规划)
摘要:SequenceTime Limit: 1000ms Memory limit: 65536K有疑问?点这里^_^题目描述Given an integer number sequence A of length N (1#include #include using namespace std;const int maxn=1010;int num[maxn];long long sum[maxn];long long dp[maxn];int min(int a,int b){ return a>b?b:a;}int main(){ int t;cin>>t; int n, 阅读全文

posted @ 2014-04-24 17:12 恒邪 阅读(177) 评论(0) 推荐(0)

快速幂运算
摘要:#include #include using namespace std;#define mod 100007int mi(int d,int n)//快速幂运算 思想 2的4次方可以 2的平方乘以2的平凡{ int ans=1; while(n) { if(n%2==1) ans=ans*d%mod;//这条语句肯定执行的 d=d*d%mod; n/=2; } return ans;}int main(){ cout<<mi(2,5)<<endl; return 0;} 阅读全文

posted @ 2014-04-24 17:10 恒邪 阅读(176) 评论(0) 推荐(0)

山东省acm省赛 I Sequence(动态规划)
摘要:SequenceTime Limit: 1000ms Memory limit: 65536K有疑问?点这里^_^题目描述Given an integer number sequence A of length N (1 2 #include 3 #include 4 #include 5 #... 阅读全文

posted @ 2014-04-24 15:41 恒邪 阅读(319) 评论(0) 推荐(0)

[ACM] 携程预赛第一场 括号匹配 (动态规划)
摘要:括号匹配Time Limit : 2000/1000ms (Java/Other)Memory Limit : 32768/32768K (Java/Other)Total Submission(s) : 110Accepted Submission(s) : 46Font:Times New Roman|Verdana|GeorgiaFont Size:←→Problem Description描述 给你一个字符串,里面只包含"(",")","[","]"四种符号,请问你需要至少添加多少个括号才能使这些括号匹配起 阅读全文

posted @ 2014-04-22 20:44 恒邪 阅读(187) 评论(0) 推荐(0)

[ACM] poj 1141 Brackets Sequence (动态规划)
摘要:Brackets SequenceTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 23884Accepted: 6727Special JudgeDescriptionLet us define a regular brackets sequence in the following way:1. Empty sequence is a regular sequence. 2. If S is a regular sequence, then (S) and [S] are both regular sequences. 3. 阅读全文

posted @ 2014-04-22 20:39 恒邪 阅读(161) 评论(0) 推荐(0)

线段树_入门
摘要:线段树是一种二叉搜索树,与区间树相似,它将一个区间划分成一些单元区间,每个单元子表示的区间为[a,(a+b)/2],右儿子表示本的线段树结构,但只有这些并不能做什么,就好比一个程序有输入没输出,根本没有任何用处。 录线段有否被覆盖,并随时查询当前被覆盖线段的总长度。那么此时可以在结点结构中加入一个变... 阅读全文

posted @ 2014-04-22 20:25 恒邪 阅读(177) 评论(0) 推荐(0)

hdu acm 4259 Double Dealing (置换群)
摘要:Double DealingTime Limit: 50000/20000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1708Accepted Submission(s): 585Pro... 阅读全文

posted @ 2014-04-22 19:03 恒邪 阅读(327) 评论(0) 推荐(0)

北大计算机研究生的ACM感言
摘要:时间过得真快,转眼间现在马上就到了毕业的时候了。大学四年的生活就这样在漫不经心中度过,在这四年里我留下了许多值得回忆的东西。参加acm的经历和体会和其他美好的经历一样,永远值得我回忆和珍惜。一个偶然,我报考了兰州大学计算机科学与技术系;又一个偶然,我开始了解acm,开始慢慢喜欢上acm。我相信这都不是偶然,或许是我们所说的缘分。2003年我从一个小县城来到兰州大学,那时我计算机几乎没有任何了解,也从来没有接触过计算机。现在我还清楚的记得大一时的上机课,我在internet explore的地址栏里面练习了三个小时的打字,为知道了如何实现大小写字母的转换而欣喜。回想起那时的自己真的感到很幼稚,但 阅读全文

posted @ 2014-04-22 12:06 恒邪 阅读(309) 评论(0) 推荐(0)

[ACM] hdu 2844 Coins (多重背包)
摘要:CoinsTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6347Accepted Submission(s): 2589Problem DescriptionWhuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One day Hibix opened purse and found there were some coins. He dec 阅读全文

posted @ 2014-04-22 11:28 恒邪 阅读(321) 评论(0) 推荐(0)

[ACM] hdu 2191 珍惜现在,感恩生活 (多重背包)
摘要:Problem Description急!灾区的食物依然短缺!为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并且只能整袋购买。请问:你用有限的资金最多能采购多少公斤粮食呢?后记:人生是一个充满了变数的生命过程,天灾、人祸、病痛是我们生命历程中不可预知的威胁。月有阴晴圆缺,人有旦夕祸福,未来对于我们而言是一个未知数。那么,我们要做的就应该是珍惜现在,感恩生活——感谢父母,他们给予我们生命,抚养我们成人;感谢老师,他们授给我们知识,教我们做人感谢朋友,他们让我们感受到世界的温暖;感谢对手,他们令我 阅读全文

posted @ 2014-04-22 11:24 恒邪 阅读(149) 评论(0) 推荐(0)

[ACM] hrbustoj 1161 Leyni (树状数组)
摘要:LeyniTime Limit: 3000 MSMemory Limit: 65536 KTotal Submit: 247(56 users)Total Accepted: 78(53 users)Rating:Special Judge:NoDescriptionLeyni被人掳走,身在水深火热之中...小奈叶为了拯救Leyni,独自一人前往森林深处从静竹手中夺回昏迷中的Leyni。历经千辛万苦,小奈叶救出了Leyni,但是静竹为此极为恼怒,决定对他们发起最强烈的进攻。不过小奈叶有一个叫做能量保护圈的道具,可以保护他们。这个保护圈由n个小的小护盾围成一圈,从1到n编号。当某一块小护盾受到攻 阅读全文

posted @ 2014-04-22 10:08 恒邪 阅读(183) 评论(0) 推荐(0)

[2011山东ACM省赛] Identifiers(模拟)
摘要:IdentifiersTime Limit: 1000ms Memory limit: 65536K有疑问?点这里^_^题目描述Identifier is an important concept in the C programming language. Identifiers provide names for several language elements, such as functions, variables, labels, etc.An identifier is a sequence of characters. A valid identifier can conta 阅读全文

posted @ 2014-04-21 21:25 恒邪 阅读(134) 评论(0) 推荐(0)

[ACM] hrbustoj 1400 汽车比赛 (树状数组)
摘要:汽车比赛Time Limit: 1000 MSMemory Limit: 65536 KTotal Submit: 188(56 users)Total Accepted: 72(50 users)Rating:Special Judge:NoDescriptionXianGe非常喜欢赛车比赛尤其是像达喀尔拉力赛,这种的比赛规模很大,涉及到很多国家的车队的许多车手参赛。XianGe也梦想着自己能举办一个这样大规模的比赛,XianGe幻想着有许多人参赛,那是人山人海啊,不过XianGe只允许最多100000人参加比赛。这么大规模的比赛应该有技术统计,在XianGe的比赛中所有车辆的起始点可能不同 阅读全文

posted @ 2014-04-21 20:35 恒邪 阅读(215) 评论(0) 推荐(0)

[2011山东ACM省赛] Binomial Coeffcients(求组合数)
摘要:Binomial CoeffcientsTime Limit: 1000ms Memory limit: 65536K有疑问?点这里^_^题目描述输入输出示例输入31 110 2954 723示例输出1453557658提示来源山东省第二届ACM大学生程序设计竞赛解题思路:这道题坑死我了。。本来很简单的一道题,却怎么也做不对。。就是求组合数,结果对10000003取模。一开始对c(m,n)是用公式直接求的,但是计算过程中涉及到取余,不能用以下代码写:int c(int m,int n){ int sum=1; for(int i=1;i#include using namespac... 阅读全文

posted @ 2014-04-20 17:57 恒邪 阅读(218) 评论(0) 推荐(0)

[2011山东ACM省赛] Mathman Bank(模拟题)
摘要:Mathman BankTime Limit: 1000ms Memory limit: 65536K有疑问?点这里^_^题目描述With the development of mathmen's mathematics knowlege, they have finallyinvented computers. Therefore, they want to use computers to manage theirbanks. However, mathmen's programming skills are not as good as theirmath- ematic 阅读全文

posted @ 2014-04-20 17:30 恒邪 阅读(178) 评论(0) 推荐(0)

[ACM] hdu 2352 Stars (树状数组)
摘要:StarsTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 30272Accepted: 13206DescriptionAstronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to 阅读全文

posted @ 2014-04-19 20:53 恒邪 阅读(174) 评论(0) 推荐(0)

[ACM] hdu 1166 敌兵布阵(树状数组)
摘要:敌兵布阵Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 36928Accepted Submission(s): 15589Problem DescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人 阅读全文

posted @ 2014-04-19 19:02 恒邪 阅读(114) 评论(0) 推荐(0)

[ACM] poj 3468 A Simple Problem with Integers(线段树,成段更新,懒惰标记)
摘要:A Simple Problem with IntegersTime Limit: 5000MSMemory Limit: 131072KTotal Submissions: 55273Accepted: 16628Case Time Limit: 2000MSDescriptionYou have N integers, A1, A2, ... ,AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a giv 阅读全文

posted @ 2014-04-17 21:39 恒邪 阅读(117) 评论(0) 推荐(0)

[ACM] hdu 2795 Billboard (线段树)
摘要:BillboardTime Limit: 20000/8000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8962Accepted Submission(s): 3997Problem DescriptionAt the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the 阅读全文

posted @ 2014-04-17 20:40 恒邪 阅读(172) 评论(0) 推荐(0)

[ACM] hdu 1698 Just a Hook (线段树,成段更新,懒惰标记)
摘要:Just a HookTime Limit: 4000/2000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14942Accepted Submission(s): 7409Problem DescriptionIn the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecu 阅读全文

posted @ 2014-04-17 12:59 恒邪 阅读(161) 评论(0) 推荐(0)

ACM hdu 1028 Ignatius and the Princess III
摘要:Ignatius and the Princess IIITime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11692Accepted Submiss... 阅读全文

posted @ 2014-04-17 11:19 恒邪 阅读(161) 评论(0) 推荐(0)

[2010山东ACM省赛] Ivan comes again!(set 的使用)
摘要:Ivan comes again!Time Limit: 1000ms Memory limit: 65536K有疑问?点这里^_^题目描述The Fairy Ivan gave Saya three problems to solve (Problem F). After Saya finished the first problem (Problem H), here comes the second.This is the enhanced version of Problem H.There is a large matrix whose row and column are less 阅读全文

posted @ 2014-04-16 20:45 恒邪 阅读(191) 评论(0) 推荐(0)

[ACM] hdu 1754 I Hate It (线段树,单点更新)
摘要:I Hate ItTime Limit: 9000/3000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 33125Accepted Submission(s): 13059Problem Description很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。Input本题目包含多组测试,请处理到文件结束。在每 阅读全文

posted @ 2014-04-16 19:21 恒邪 阅读(142) 评论(0) 推荐(0)

[ACM] hdu 1166 敌兵布阵 (线段树,单点更新)
摘要:敌兵布阵Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 36806Accepted Submission(s): 15545Problem DescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人 阅读全文

posted @ 2014-04-16 08:48 恒邪 阅读(175) 评论(0) 推荐(0)

[ACM] poj 1182 食物链(并查集)
摘要:食物链Time Limit:1000MSMemory Limit:10000KTotal Submissions:41200Accepted:11988Description动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。现有N个动物,以1-N编号。每个... 阅读全文

posted @ 2014-04-15 14:22 恒邪 阅读(229) 评论(0) 推荐(0)

[ACM] hdu 1272 小希的迷宫(并查集)
摘要:小希的迷宫Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 23418Accepted Submission(s): 7186Problem Description上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B,那么既可以通过它从房间A走到房间B,也可以通过它从房间B走到房间A,为了提 阅读全文

posted @ 2014-04-15 13:26 恒邪 阅读(167) 评论(0) 推荐(0)

[ACM] hdu 1198 Farm Irrigation (看图枚举+并查集)
摘要:Farm IrrigationTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4962Accepted Submission(s): 2130Problem DescriptionBenny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot of samll squares. Water pipes are 阅读全文

posted @ 2014-04-15 11:33 恒邪 阅读(139) 评论(0) 推荐(0)

[ACM] 携程预赛第二场 剪刀石头布(并查集)
摘要:剪刀石头布Time Limit : 2000/1000ms (Java/Other)Memory Limit : 32768/32768K (Java/Other)Total Submission(s) : 47Accepted Submission(s) : 18Font:Times New Roman|Verdana|GeorgiaFont Size:←→Problem Description现有M个人一起玩剪刀石头布,以1-M编号,每人出一种,出过不再改变,但是我们并不知道它到底是哪一种。 (其中石头赢剪刀,剪刀赢布,布赢石头,一样则平)裁判用两种说法对这M个人所构成的输赢关系进行描述: 阅读全文

posted @ 2014-04-15 10:17 恒邪 阅读(307) 评论(0) 推荐(0)

[ACM] hdu 1241 Oil Deposits(DFS)
摘要:Oil DepositsTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10647Accepted Submission(s): 6179Problem DescriptionThe GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangu 阅读全文

posted @ 2014-04-14 21:36 恒邪 阅读(232) 评论(0) 推荐(0)

Jerry Mouse
摘要:Jerry MouseTime Limit: 1000ms Memory limit: 65536K^_^题目描述Kudo and Saya are good friends, and they are always together.But today, since Saya is not her... 阅读全文

posted @ 2014-04-14 14:40 恒邪 阅读(513) 评论(0) 推荐(0)

[2010山东ACM省赛] Balloons(搜索)
摘要:BalloonsTime Limit: 1000ms Memory limit: 65536K有疑问?点这里^_^题目描述Both Saya and Kudo like balloons. One day, they heard that in the central park, there will be thousands of people fly balloons to pattern a big image.They were very interested about this event, and also curious about the image.Since there 阅读全文

posted @ 2014-04-13 17:47 恒邪 阅读(222) 评论(0) 推荐(0)

Greatest Number
摘要:Greatest NumberTime Limit: 1000ms Memory limit: 65536K^_^题目描述Saya likes math, because she think math can make her cleverer.One day, Kudo invited a ver... 阅读全文

posted @ 2014-04-13 17:02 恒邪 阅读(878) 评论(0) 推荐(0)

[2010山东ACM省赛] Greatest Number(数的组合+二分搜索)
摘要:Greatest NumberTime Limit: 1000ms Memory limit: 65536K有疑问?点这里^_^题目描述Saya likes math, because she think math can make her cleverer.One day, Kudo invited a very simple game:GivenNintegers, then the players choose no more than four integers from them (can be repeated) and add them together. Finally, th 阅读全文

posted @ 2014-04-13 16:01 恒邪 阅读(283) 评论(0) 推荐(0)

[ACM] hdu 1213 How Many Tables(并查集)
摘要:How Many TablesTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11580Accepted Submission(s): 5696Problem DescriptionToday is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he nee 阅读全文

posted @ 2014-04-12 20:42 恒邪 阅读(209) 评论(0) 推荐(0)

携程预赛第二场 1002 位图像素的颜色
摘要:位图像素的颜色Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 0Accepted Submission(s): 0Problem Description有一个在位图上画出矩形程序,一开始位图都被初始化为白色(RGB颜色表示为R=G=B=255)。该程序能够按照顺序绘出N个矩形。新绘制的矩形能够覆盖位图上原有的颜色。程序执行完毕后,需要查询M个点的颜色,输出这些点的RGB值。每组数据都是在初始化后开始绘制。Input第一行包含参数N和M,分别表示 阅读全文

posted @ 2014-04-11 21:14 恒邪 阅读(160) 评论(0) 推荐(0)

[ACM] hdu 1536 S-Nim(Nim组合博弈 SG函数打表)
摘要:S-NimTime Limit: 5000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4004Accepted Submission(s): 1732Problem DescriptionArthur and his sister Caroll have been playing a game called Nim for some time now. Nim is played as follows:The starting position has a number 阅读全文

posted @ 2014-04-11 15:00 恒邪 阅读(223) 评论(0) 推荐(0)

[ACM] hdu 1848 Fibonacci again and again(Nim博弈 SG函数)
摘要:Fibonacci again and againTime Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4152Accepted Submission(s): 1735Problem Description任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1)=1;F(2)=2;F(n)=F(n-1)+F(n-2)(n>=3);所以,1,2,3,5,8,13……就是菲波那契数列。在HDOJ上有 阅读全文

posted @ 2014-04-11 08:49 恒邪 阅读(224) 评论(0) 推荐(0)

[ACM] hdu 2176 取(m堆)石子游戏(Nim博弈)
摘要:取(m堆)石子游戏Time Limit: 3000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1466Accepted Submission(s): 853Problem Descriptionm堆石子,两人轮流取.只能在1堆中取.取完者胜.先取者负输出No.先取者胜输出Yes,然后输出怎样取子.例如5堆 5,7,8,9,10先取者胜,先取者第1次取时可以从有8个的那一堆取走7个剩下1个,也可以从有9个的中那一堆取走9个剩下0个,也可以从有10个的中那一堆取走7个剩下3个 阅读全文

posted @ 2014-04-09 21:03 恒邪 阅读(288) 评论(0) 推荐(0)

[ACM] hdu 1850 Being a Good Boy in Spring Festival(Nim博弈)
摘要:Being a Good Boy in Spring FestivalTime Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3819Accepted Submission(s): 2269Problem Description一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里尝试做做下面的事情吧陪妈妈逛一次菜场悄悄给爸爸买个小礼物主动地 强烈地 要求洗一次碗某一天早起 给爸妈用心地做回早餐如果愿意 你还可以和爸妈说咱们玩个小游戏吧 ACM课上学 阅读全文

posted @ 2014-04-09 20:48 恒邪 阅读(170) 评论(0) 推荐(0)

母函数
摘要:这里先给出2个例子,等会再结合题目分析: 第一种:有1克、2克、3克、4克的砝码各一 枚,能称出哪几种重量?每种重量各有几种可能方案? 考虑用母函数来解决这个问题: 我们假设x表示砝码,x的指数表示砝码的重量,这样: 1个1克的砝码可以用函数1+x表示, 1个2克的砝码可以用函数1+x2 表示, 1个3克的砝码可以用函数1+x3表示, 1个4克的砝码可以用函数1+x4表示, 上面这四个式子懂吗? 我们拿1+x2 来说,前面已经说过,x表示砝码,x的指数表示重量,即这里就是一个质量为2的砝码,那么前面的1表示什么?1代表重量为2的砝码数量为0个。(理解!) 不知道大家理解没,我们这里结合前面那句 阅读全文

posted @ 2014-04-09 19:52 恒邪 阅读(251) 评论(0) 推荐(0)

Euclid算法(欧几里得算法)
摘要:线性组合与GCD现在我们证明一个重要的定理:gcd(a,b)是a和b的最小的正线性组合。证明:设gcd(a,b)为d,a和b的最小的正线性组合为s∵d|a且d|b,∴d|s。而a mod s=a-[a/s]s =a-[a/s](ax+by) =a(1-[a/s]x)-b[a/s]y亦为a和b的线性组合∵a mod s=b。用辗转相减法时,必须先判断大小,而Euclid算法不然。若a<b,则一次递归就会转为gcd(b,a),接着就能正常运行了。 阅读全文

posted @ 2014-04-08 20:17 恒邪 阅读(1982) 评论(0) 推荐(0)

用线性组合表示两个数的最大公约数
摘要:用辗转相除法就OK了举个例子求(42,15)并用42和15线性表示(42,15)解:利用辗转相除法42=15*2+12①15=12*1+3②12=3*4③所以(42,15)=(15,12)=(12,3)=3由①有12=42-15*2代入②得3=15-12=15-(42-15*2)=-42+15*3所以(42,15)=-42+15*3=3即为所求一般地设整数a和b,有辗转除法a=bq1+r1(0=2)则有aQk-bPk=(-1)^(k-1)*rk(k=1,2,……,n) 阅读全文

posted @ 2014-04-08 20:08 恒邪 阅读(787) 评论(0) 推荐(0)

[ACM] poj 2484 A Funny Game(对称博弈)
摘要:A Funny GameTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 3795Accepted: 2268DescriptionAlice and Bob decide to play a funny game. At the beginning of the game they pick n(1 3, we use c1, c2, ..., cn to denote the coins clockwise and if Alice remove c2, then c1 and c3 are NOT adjacent! (B. 阅读全文

posted @ 2014-04-08 19:54 恒邪 阅读(165) 评论(0) 推荐(0)

[ACM] hdu 2177 取(2堆)石子游戏(威佐夫博弈)
摘要:Problem Description有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆中同时取走相同数量的石子。最后把石子全部取完者为胜者。现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是败者。如果你胜,你第1次怎样取子?Input输入包含若干行,表示若干种石子的初始情况,其中每一行包含两个非负整数a和b,表示两堆石子的数目,a和b都不大于1,000,000,且a#include #include #include using namespace std; 阅读全文

posted @ 2014-04-08 19:36 恒邪 阅读(263) 评论(0) 推荐(0)

POJ-2142The Balance
摘要:The BalanceTime Limit:5000MSMemory Limit:65536KTotal Submissions:2378Accepted:1041DescriptionMs. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine. For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight 阅读全文

posted @ 2014-04-08 19:32 恒邪 阅读(166) 评论(0) 推荐(0)

[ACM] poj 1067 取石子游戏(威佐夫博奕)
摘要:取石子游戏Time Limit: 1000MSMemory Limit: 10000KTotal Submissions: 33061Accepted: 10990Description有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆中同时取走相同数量的石子。最后把石子全部取完者为胜者。现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是败者。Input输入包含若干行,表示若干种石子的初始情况,其中每一行包含两个非负整数a和b,表示两堆石子的数目,a和b都不大 阅读全文

posted @ 2014-04-08 10:40 恒邪 阅读(202) 评论(0) 推荐(0)

[ACM] hdu 2079 选课时间(普通型母函数)
摘要:Problem Description又到了选课的时间了,xhd看着选课表发呆,为了想让下一学期好过点,他想知道学n个学分共有多少组合。你来帮帮他吧。(xhd认为一样学分的课没区别)Input输入数据的第一行是一个数据T,表示有T组数据。每组数据的第一行是两个整数n(1 #include using namespace std;int c[45],temp[45];int a[11],b[11];int main(){ int t;cin>>t; int n,k; while(t--) { cin>>n>>k; for(int i=1;i>a... 阅读全文

posted @ 2014-04-07 21:36 恒邪 阅读(195) 评论(0) 推荐(0)

[ACM] poj 1496 Word Index(组合计数)
摘要:Word IndexTime Limit: 1000MSMemory Limit: 10000KTotal Submissions: 4541Accepted: 2567DescriptionEncoding schemes are often used in situations requiring encryption or information storage/transmission economy. Here, we develop a simple encoding scheme that encodes particular types of words with five o 阅读全文

posted @ 2014-04-07 21:09 恒邪 阅读(240) 评论(0) 推荐(0)

扩展欧几里德算法
摘要:不定方程ax+by=c重点:解二元一次不定方程。看起来扩展Euclid算法是不定方程的一种特殊情况,实际上呢,不定方程却是用Euclid算法解的。对 于不定方程ax+by=c,设gcd(a,b)=d,如果ax+by=c有解,则d|c(这也是许多奥数题的切入点)。所以一旦d不是c的约数,那么 ax+by=c一定无解。当d|c时,先求出ax'+by'=d=gcd(a,b)的x'和y',则x=x'*c/d,y=y'*c/d。由上一段可知, 只要ax+by=c有一个解,它就有无数个解。Euclid算法还可以求解同余方程ax≡b(mod m)。这其实和不定 阅读全文

posted @ 2014-04-07 20:48 恒邪 阅读(268) 评论(0) 推荐(0)

哈理工OJ-1328 相等的最小公倍数
摘要:题目描述 定义 An 为 1,2,…,n 的最小公倍数,例如,A1=1,A2=2,A3=6,A4=12,5=60,A6=60。 请你判断对于给出的任意整数 n,An 是否等于 An–1。如果 An 等于An-1则输出 YES 否则输出 NO。分析 由最小公倍数的定义我们可以知道,如果 An=An-1 则 An-1 可以被 n 整除,首先,对于一个数 n 如果是素数,那么 An 不等于 An-1,其次,我们分析 n,如果对于小于 n 的每一对因子即 n=a*b(a1,则 lcm(a,b)=n/gcd(a,b) 2 #include 3 #include 4 using namespace st. 阅读全文

posted @ 2014-04-07 20:09 恒邪 阅读(354) 评论(1) 推荐(0)

[ACM] hdu 1134 Game of Connections(大数+Catalan数)
摘要:Game of ConnectionsTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2923Accepted Submission(s): 1649Problem DescriptionThis is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, ... , 2n - 1, 2n consecutively in clockwise 阅读全文

posted @ 2014-04-07 19:34 恒邪 阅读(163) 评论(0) 推荐(0)

欧几里得算法
摘要:什么是GCD?GCD是最大公约数的简称(当然理解为我们伟大的党也未尝不可)。在开头,我们先下几个定义: ①a|b表示a能整除b(a是b的约数) ②a mod b表示a-[a/b]b([a/b]在Pascal中相当于a div b) ③gcd(a,b)表示a和b的最大公约数 ④a和b的线性组合表示ax+by(x,y为整数)。我们有:若d|a且d|b,则d|ax+by(这很重要!)欧几里得算法又称为辗转相除法,设两个数 a,b则 a,b的最大公约 gcd(a,b)=gcd(b,a%b) 不妨设 a>=b,c=gcd(a,b),a=kc,b=jc,则 k,j 互素(否则 c 不是 a,b 的最 阅读全文

posted @ 2014-04-07 19:10 恒邪 阅读(209) 评论(0) 推荐(0)

组合数打表
摘要:代码:#include #include using namespace std;int c[11][11];void init(){ memset(c,0,sizeof(c)); c[0][0]=c[1][0]=c[1][1]=1; for(int i=2;i<=10;i++) { c[i][0]=c[i][i]=1; for(int j=1;j<i;j++) c[i][j]=c[i-1][j]+c[i-1][j-1]; }}int main(){ init(); cout<<c[3][2]<<end... 阅读全文

posted @ 2014-04-07 16:50 恒邪 阅读(159) 评论(0) 推荐(0)

[ACM] hdu 1521 排列组合(指数型母函数)
摘要:排列组合Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2132Accepted Submission(s): 877Problem Description有n种物品,并且知道每种物品的数量。要求从中选出m件物品的排列数。例如有两种物品A,B,并且数量都是1,从中选2件物品,则排列有"AB","BA"两种。Input每组输入数据有两行,第一行是二个数n,m(1#include #include #incl 阅读全文

posted @ 2014-04-07 14:38 恒邪 阅读(211) 评论(0) 推荐(0)

hdu acm 1051 sticks
摘要:看上去并不是很复杂的深搜题,很容易写出可通过测试的代码,但要注意剪枝,这类搜索题考察对剪枝的要求一直没发现,以至于一直TLE。。。虽然代码写得快,但是考虑优化时极其浪费时间,最后在各方面的帮助下 还是写出了AC的代码 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 8 int n,falg,a[70],vis[70],ans; 9 void dfs(int fa,int s,int c)10 {11 12 if(c==1){falg=0;return;}13 if(fa==... 阅读全文

posted @ 2014-04-07 14:28 恒邪 阅读(156) 评论(0) 推荐(0)

[ACM] hdu 1521 排列组合(组合+DFS)
摘要:排列组合Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2119Accepted Submission(s): 875Problem Description有n种物品,并且知道每种物品的数量。要求从中选出m件物品的排列数。例如有两种物品A,B,并且数量都是1,从中选2件物品,则排列有"AB","BA"两种。Input每组输入数据有两行,第一行是二个数n,m(1#include using namespac 阅读全文

posted @ 2014-04-06 23:16 恒邪 阅读(709) 评论(0) 推荐(0)

[ACM] hdu 1864 最大报销额(01背包或贪心)
摘要:最大报销额Time Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14982Accepted Submission(s): 4240Problem Description现有一笔经费可以报销一定额度的发票。允许报销的发票类型包括买图书(A类)、文具(B类)、差旅(C类),要求每张发票的总额不得超过1000元,每张发票上,单项物品的价值不得超过600元。现请你编写程序,在给出的一堆发票中找出可以报销的、不超过给定额度的最大报销额。Input测试输入包含若 阅读全文

posted @ 2014-04-06 23:05 恒邪 阅读(349) 评论(0) 推荐(0)

[ACM] hdu 2067 小兔的棋盘(卡特兰数Catalan)
摘要:小兔的棋盘Time Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5814Accepted Submission(s): 3186Problem Description小兔的叔叔从外面旅游回来给她带来了一个礼物,小兔高兴地跑回自己的房间,拆开一看是一个棋盘,小兔有所失望。不过没过几天发现了棋盘的好玩之处。从起点(0,0)走到终点(n,n)的最短路径数是C(2n,n),现在小兔又想如果不穿越对角线(但可接触对角线上的格点),这样的路径数有多少?小兔想了很 阅读全文

posted @ 2014-04-05 20:57 恒邪 阅读(765) 评论(0) 推荐(0)

[ACM] poj 2249 Binomial Showdown (排列组合公式优化)
摘要:DescriptionIn how many ways can you choose k elements out of n elements, not taking order into account?Write a program to compute this number. InputThe input will contain one or more test cases. Each test case consists of one line containing two integers n (n>=1) and k (0using namespace std;const 阅读全文

posted @ 2014-04-05 20:02 恒邪 阅读(205) 评论(0) 推荐(0)

队列逆置
摘要:思路:用一个栈起到过渡的作用。先将队列中的元素放入栈中,然后初始化队列,再将元素从栈中取出放到初始化的队列中。代码:#include #include #include using namespace std;const int maxn=10;typedef struct{ char data[maxn]; int front,rear;}Queue;typedef struct{ char data[maxn]; int top;}Stack;void Reverse(Queue &q,Stack &s){ s.top=-1; while(q.front... 阅读全文

posted @ 2014-04-05 14:34 恒邪 阅读(214) 评论(0) 推荐(0)

[ACM] 括号匹配问题(栈的使用)
摘要:括号配对问题时间限制:3000 ms | 内存限制:65535 KB难度:3描述 现在,有一行括号序列,请你检查这行括号是否配对。输入 第一行输入一个数N(0#include #include using namespace std;char e[10000];bool match(stack s,char e[],int n){ for(int i=0;i>t; while(t--) { cin>>e; int len=strlen(e); stacks; if(match(s,e,len)) c... 阅读全文

posted @ 2014-04-05 13:18 恒邪 阅读(191) 评论(0) 推荐(0)

超有意思的小学编程题
摘要:由于小学生所拥有的计算方法有限(他不会用函数,数组,循环,判断等一系列复杂语法结构)Problem E: 武功秘籍Time Limit: 1 SecMemory Limit: 128 MBDescription小明到X山洞探险,捡到一本有破损的武功秘籍(2000多页!当然是伪造的)。 他注意到:书的第10页和第11页在同一张纸上,但第11页和第12页不在同一张纸上 。小明只想练习该书的第a页到第b页的武功,又不想带着整本书。请问他至少要撕下多少张纸带走?Input有多组测试实例,输入小明想要练习的起始页a和末尾页b。(a 2 #include 3 using namespace std; 4. 阅读全文

posted @ 2014-04-04 19:39 恒邪 阅读(1920) 评论(0) 推荐(0)

[ACM] hdu 1286 找新朋友(欧拉函数)
摘要:找新朋友Time Limit: 2000/1000 MS(Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s):6928Accepted Submission(s): 3593Problem Description新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来。Input第一行是测试数据的组数CN(Casenu 阅读全文

posted @ 2014-04-02 20:39 恒邪 阅读(167) 评论(0) 推荐(0)

环形队中实现队列的基本运算
摘要:/*队空条件:front=rear队满条件:(rear+1)%MaxSize=front进队e操作:rear=(rear+1)%MaxSize; 将e放在rear处出队操作:front=(front+1)%MaxSize;取出front处元素e; */#include #include using namespace std;const int maxn=4;typedef struct{ int data[maxn]; int front,rear;}queue;//初始化队列void init(queue *&q){ q=(queue*)malloc(sizeof(que... 阅读全文

posted @ 2014-04-02 19:17 恒邪 阅读(356) 评论(0) 推荐(0)

队列的顺序存储结构及其基本运算的实现
摘要:代码:#include #include using namespace std;const int maxn=500;typedef struct{ int data[maxn]; int front,rear;}queue;//初始化队列void init(queue *&q){ q=(queue*)malloc(sizeof(queue)); q->rear=q->front=-1;}//销毁队列void destroy(queue *&q){ free(q);}//判断队列是否为空bool empty(queue *&q){ return q-> 阅读全文

posted @ 2014-04-02 18:56 恒邪 阅读(304) 评论(0) 推荐(0)

栈的链式存储结构及其基本运算实现
摘要:#include #include using namespace std;typedef struct linknode{ int data; struct linknode *next;}Listack;//初始化栈void init(Listack *&s){ s=(Listack*)malloc(sizeof(Listack)); s->next=NULL;}//摧毁栈void destroy(Listack *&s){ Listack *p=s,*q=s->next; while(q!=NULL) { free(p); ... 阅读全文

posted @ 2014-04-02 18:21 恒邪 阅读(215) 评论(0) 推荐(0)

栈的顺序存储结构及其基本运算实现
摘要:#include #include using namespace std;const int maxn=500;typedef struct { int data[maxn]; int top;}Stack;//初始化stackvoid init(Stack *&s){ s=(Stack *)malloc(sizeof(Stack)); s->top=-1;}//销毁stackvoid destroy(Stack *&s){ free(s);}//判断栈是否为空bool empty(Stack *s){ return (s->top==-1);}//进stackv 阅读全文

posted @ 2014-04-02 18:20 恒邪 阅读(196) 评论(0) 推荐(0)

[ACM] hdu 1205 吃糖果(鸽巢原理)
摘要:吃糖果Time Limit: 6000/3000 MS (Java/Others)Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 21695Accepted Submission(s): 6185Problem DescriptionHOHO,终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一种,这样;可是Gardon不知道是否存在一种吃糖果的顺序使得他能把所有糖果都吃完?请你写个程序帮忙计算一下。Input第一行有一个整数T 阅读全文

posted @ 2014-04-01 11:05 恒邪 阅读(273) 评论(0) 推荐(0)

[ACM] poj 3128 Leonardo's Notebook (置换群,循环节)
摘要:Leonardo's NotebookTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 1791Accepted: 787Description— I just bought Leonardo's secret notebook! Rare object collector Stan Ucker was really agitated but his friend, special investigator Sarah Kepticwas unimpressed.— How do you know it is ge 阅读全文

posted @ 2014-04-01 10:43 恒邪 阅读(219) 评论(0) 推荐(0)

导航