随笔分类 - HDOJ
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1005找循环节。。 1 #include 2 #include 3 const int N=52; 4 int f[N]; 5 int main() 6 { 7 int a,b,n; 8 while(~scanf("%d%d%d",&a,&b,&n)) 9 {10 int s,e;11 if (a==0&&b==0&&n==0)12 break;13 f[0] = 1;14 f[1] = 1;1...
阅读全文
摘要: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.hdu.edu.cn/showproblem.php?pid=1025题意:富人路与穷人路都分别有从1到n的n个点,现在要在富人点与穷人点之间修路,但是要求路不能交叉,问最多能修多少条。思路:穷人路是按顺序给的,故求富人路的最长上升子序列即可。由于数据范围太大,应该用O(nlogn)的算法求LIS。 1 #include 2 #include 3 #include 4 using namespace std; 5 const int N=500005; 6 int r[N],d[N]; 7 int main() 8 { 9 int n,cnt = 0,x,y...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1429 1 #include 2 #include 3 #include 4 using namespace std; 5 struct node 6 { 7 int x,y; 8 int state; 9 int step; 10 } s,t; 11 int Time,n,m; 12 int s_x,s_y,e_x,e_y; 13 char a[32][32]; 14 int vis[32][32][1026];//标记状态 15 int dir[4][2] ...
阅读全文
摘要:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=35800#problem/D 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 const int INF=1p[N]; 14 mapname_id; 15 mappos_id; 16 int value[N],link[N][N],ans; 17 18 int res() 19 { 20 i...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4712题意:计算任意两个十六进制的数异或后1的最少个数。思路:用随机数随机产生两个数作为下标,记录这两个数异或后1的个数,输出1的个数最少是多少。 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 const int N=100002; 8 const int INF=1<<29; 9 int f[N];10 int main()11 {12 int t;13 scanf("%d",&a
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4715题意:给一个偶数,将这个偶数用两个最小的素数表示,如果不能表示则输出FALL; 注意给定的偶数可能为负值。思路:素数打表,将给定的数从第一个素数开始相加,判断相加后的值是否为素数。 1 #include 2 #include 3 4 const int N=1000050; 5 int f[N],p[N/2]; 6 int num;//1e6内素数个数 7 8 void is_prime() 9 {10 f[1] = 0;11 f[2] = 1;12 for (int i...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4707题意:判断距离大于D的点有多少个。思路: 邻接表建图,dfs每一个点,记录步数。 1 #include 2 #include 3 const int N=200002; 4 int vis[N],dis[N],head[N],cnt,step; 5 struct node 6 { 7 int u; 8 int v; 9 int next;10 } edge[N];11 void add(int u,int v)12 {13 edge[cnt].u = u;14 ...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1272思路:所求的图满足两点要求:(1) 连通 (2) 不存在环 。而这两点用并查集都能判断。注意本题中 输入 0 0时,应输出 Yes。 1 #include 2 #include 3 const int N=100002; 4 int f[N],vis[N]; 5 void init() 6 { 7 for (int i = 1; i <= N; i ++) 8 { 9 f[i] = i;10 vis[i] = 0;11 }12 13 }14 i...
阅读全文

浙公网安备 33010602011771号