03 2014 档案
摘要:B. Long Pathtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day, little Vasya found himself in a maze consisting of(n + 1)rooms, numbered from1to(n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the(
阅读全文
摘要:C. Triangletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a right triangle with legs of lengthaandb. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1754简单线段树题,单点更新+区间求最大值。 1 #include 2 #include 3 #include 4 using namespace std; 5 const int N=200002; 6 int a[N],ans = 0; 7 struct node 8 { 9 int l,r;10 int Max;11 } tree[4*N];12 void build(int root,int l,int r)13 {14 tree[root].l = l;15 t...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2986题意很简单,主要是要处理精度,最手残的是把单词拼写错了。。。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 const double eps=1e-8; 9 int main()10 {11 int n,m;12 while(~scanf("%d%d",&n,&m)){13 mapp;14 p.clear();...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2985题意:有n个人每个人可以买m轮彩票,每轮可以买尽可能多的彩票。如果该彩票在i轮被抽到,则该人可以获得2^i的奖金,问该人获得的奖金数比其他人都高的概率。思路:如果该人在第m轮中奖,则他获得的奖金数最高,如果m轮没人买彩票,则在m-1轮中奖奖金数最高。。以此类推。。求出在该轮的中奖概率即可。最后的分数输出形式通过最大公约数化简。 1 #include 2 #include 3 #include 4 #define LL __int64 5 using namespace std; 6 const i...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2992题意:有n个城市,编号为(1~n),有一些城市中有一些旅店,要求从一个城市到另一个城市不能超过10小时,问能否从1号城市到n号城市,如果能需要住的最少的旅店数目是多少。思路:首先将1号城市和n号城市置为有旅店的城市,spfa求每个旅店到其它旅店的最短距离,如果距离小于10小时,将两个旅店之间的权值置为1,这样就能构造出所有旅店之间的图,然后对该图利用floyd求最短路。 1 #include 2 #include 3 #include 4 #include 5 #include 6...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2371题意:给出一个长度为n的字符串(标号为1~n),以及n个数代表字符串的变换规则,问该字符串是由哪个字符串按照变换规则变换m次得到的?如n=5,m=3,变换规则 2 3 1 5 4(生成的下一个字符串即按照此标号的顺序对应的串),“hello" -> "elhol" -> "lhelo" -> "helol",故helol 是由"hello''变换3次得到的。思路:此类型的题目一般是找循环节,
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2372题意:给出n个数,求长度为m的递增子序列的数目。思路:状态转移方程 dp[i][j] = sum(dp[k][j-1]| k 2 #include 3 const int N=120; 4 __int64 dp[N][N]; 5 __int64 a[N]; 6 int main() 7 { 8 __int64 n,m; 9 while(~scanf("%I64d%I64d",&n,&m))10 {11 if (n==0&&m==0)12 ...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2831题意:已知A,B,C,D,E,F的坐标,求G,H的坐标,并且已知三角形DEF的面积等于平行四边形的面积,点H在AC上。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 struct Point 8 { 9 double x,y;10 Point(double x=0,double y=0):x(x),y(y) ...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2833题意:讲述了一种投小钱赢大钱的赌博方式,初始投入钱m,如果本局赢了,将钱连本带利投入下一局继续赌博。如果本局输了,之前得到的钱全部清零,如果打平,本局不赢钱。每局投入的钱数不能大于一百万,计算连本带利赢得的钱数,如果大于一百万则按赢了一百万。输入t组,然后是初始投入的钱m与赌博的局数n。在n局中,给出每局的Money Line,用于作为比率计算本局赢得的钱数。如果Money Line 大于0,则比率为Money Line/100,结果截取
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2830简单bfs 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 const int N=100005; 7 int head[N],vis[N]; 8 int cnt = 0; 9 struct Edge10 {11 int u,v;12 int next;13 } edge[4*N];14 struct node15 {16 i...
阅读全文
摘要:http://codeforces.com/problemset/problem/405/D题意:已知集合S={1,2,3......1000000},s=1000000,从集合S中选择n个数,X={x1,x2,x3,...xn},计算sum=x1-1+x2-1+....+xn-1;从剩下的元素Y={y1,y2,y3,...}中选择一些数,使得s-y1+s-y2+...=sum,输出yi的个数及yi。思路:可以根据元素的对称性来找yi。因为x-1=s-y,则y=s-x+1,即对于每一个x,对应的可选择一个y=s-x+1,如果y不在X集合中,则直接输出y。如果y也在X集合中,由于(x-1)+(y
阅读全文
摘要:http://codeforces.com/problemset/problem/405/C题意:给出一个n*n的矩阵,有q个操作,输入3时,输出A ,A等于第i行乘以第i列的对应元素的和(mod2),输入1 x,表示将第x行的元素翻转(即0变成1,1变成0),输入2 x,表示将第x列的元素翻转.思路:根据A的计算方式可知A的最终结果只由左对角线上的元素将决定,如果左对角线上的元素为1的个数有奇数个(可通过异或计算),则A=1,否则A=0。翻转的时候每翻转一行或一列,都会改变对角线的元素,故结果应异或上1. 1 #include 2 #include 3 const int N=1002;..
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3442题意:ABCD有各自的攻击力与攻击范围,刘备只能走"C"与".",问刘备从"s" 走到"!"受到的最小攻击力。ps(受过一次攻击的下次将不会再对刘备造成伤害)思路:用优先队列,每次搜索攻击力最小的,并对当前的状态标记。。。#include #include #include #include #include using namespace std;const int N=60;char Map[N][N];int a[N]
阅读全文
摘要:http://poj.org/problem?id=2661题意:Amtel在1960年发行了4位计算机,并实行每十年位数翻一番的策略,将最大整数n作为改变的等级,其中n!表示计算机的无符号整数(n!头文件中log(n)表示以e为底的n的对数)。通过累加 log(i)(i >= 1),直到和超过 k*log(2) break;则i-1即为等级。 1 #include 2 #include 3 #include 4 int main() 5 { 6 int year; 7 while(~scanf("%d",&year)&&year) 8 { 9
阅读全文
摘要:C. Searching for Graphtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call an undirected graph ofnverticesp-interesting, if the following conditions fulfill:the graph contains exactly2n + pedges;the graph doesn't contain self-loops a
阅读全文
摘要:B. Trees in a Rowtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Queen of England hasntrees growing in a row in her garden. At that, thei-th(1 ≤ i ≤ n)tree from the left has heightaimeters. Today the Queen decided to update the scenery of her
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3490题意:给出一个字符串,一个操作次数,每次操作从当前字符串最右边的字符开始,如果字符串没有数字和字母则每次使其当前字符ASCII+1,否则,如果当前字符为z(Z),则其加1后为a(A ),并向前进位1给左边的最接近自己的字符或数字,如果当前字符为9,则加1后为0,并),并向前进位1给左边的最接近自己的字符或数字。如果某个数字或字符为最左边的数字或字符,并向前进位1,则在该字符或数字左边增加一个与其相同的字符或数字。思路:理解题意并注意进位就可以了。。 1 #inclu
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1293思路:设n = x1+x2+x3.....,要使f[x] = x1*x2*x3....最大,则x1=x2=x3.... 即f[x] = x^(n/x) , 两边同时取对数得:ln(f[x]) = (n/x)lnx, 令g(x) = ln(f[x]) =(n/x)lnx,对g(x)求导 得:g(x)' = n*(1-lnx),令 g(x)' = 0 得 x = e = 2.718..... 因为x为正整数,所以x=2或x=3
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3715题意:有N个孩子投票选举leader,不能自己选自己。Sheldon想做leader,所以他就用糖果贿赂其他人,别的孩子就会将票投给他。问Sheldon最少要送多少糖果。思路:枚举Sheldon做leader的票数(Sheldon原始的票数 2 #include 3 #include 4 using namespace std; 5 const int INF=1= i)//处理所有票数比他高的51 {52 ...
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3713题意:给定一个字符串,首先输出这个字符串的长度(以两位的十六进制的形式),如果长度以二进制表示,其位数从右往左每七位分为一段,除了最后的一段,其余段在最高位前加1,然后依次以十六进制输出,如果不足七位,直接以两位十六进制输出,如果长度为0,输出00。然后输出字符串的ASCII的十六进制形式。 1 #include 2 #include 3 #include 4 using namespace std; 5 const int N=3000010; 6 cons...
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3710题意:有N个人,M对关系,(a,b)表示a,b互相认识。如果两个不认识的人有不小于K个共同朋友,则这两个人将成为新的朋友。问有多少对能成为新的好朋友。思路:枚举所有的人,如果两个人不是朋友的话,就通过两个人共同好友个数判断两个人能否成为朋友,如果两个人成为新朋友则需要重新判断没有成为朋友的人,直至没有新的朋友产生。 1 #include 2 #include 3 using namespace std; 4 5 const int N=120; 6 int m...
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3705题意:主要是分值计算要注意以下几点:(1) 在MOJ上解出的题,如果是MaoMao Selection则加2.5分,如果是来自Old Surgeon Contest则加1.5分,除了这两种情况外,如果解出的题号是素数,加1分,如果都不符合上述情况则加0.3分。(2)参加 ACM/ICPC的队伍,一等奖加36分,二等奖加27,三等奖加18分,其余不加分。(ps:一个队伍可能参加多次比赛)。(3)有rating值的按照得分公式:Pts = max(0, (r - 120
阅读全文
摘要:http://poj.org/problem?id=2533最长上升子序列的两种算法(1) O(n^2) 1 #include 2 #include 3 4 const int N=10010; 5 int dp[N],a[N];//dp[i]表示0~i的最长上升子序列的长度 6 int n; 7 8 int main() 9 {10 int n;11 while(~scanf("%d",&n))12 {13 memset(dp,0,sizeof(dp));14 for (int i = 0; i a[j] && dp[j]+1...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1159最长公共子序列 1 #include 2 #include 3 #include 4 using namespace std; 5 const int N=1010; 6 char s1[N],s2[N]; 7 int dp[N][N]; 8 9 int main()10 {11 while(~scanf("%s%s",s1,s2))12 {13 int len1 = strlen(s1);14 int len2 = strlen(s2);15 ...
阅读全文

浙公网安备 33010602011771号