
acm训练
lzh823046544
233
展开
-
Selling Cells
Selling CellsDescriptionCompetition has been fierce among the cellphone providers in the town of Eastern WestField. Several companies have been running ads in which they each claim to provide more cove原创 2016-07-08 17:13:04 · 305 阅读 · 0 评论 -
Roller Coaster
Roller CoasterDescriptionBessie has gone on a trip, and she's riding a roller coaster! Bessie really likes riding the roller coaster, but unfortunately she often gets dizzy. The roller coaster has a nu原创 2016-07-08 17:18:43 · 423 阅读 · 0 评论 -
Balloons
BalloonsDescriptionAs you may know, balloons are handed out during ACM contests to teams as they solve problems. However, this sometimes presents logistical challenges. In particular, one contest hosti原创 2016-07-08 17:09:04 · 508 阅读 · 0 评论 -
Palindrometer
PalindrometerDescriptionWhile driving the other day, John looked down at his odometer, and it read 100000. John was pretty excited about that. But, just one mile further, the odometer read 100001, and原创 2016-07-08 17:00:55 · 330 阅读 · 0 评论 -
Underground Cables
Underground CablesDescriptionA city wants to get rid of their unsightly power poles by moving their power cables underground. They have a list of points that all need to be connected, but they have som原创 2016-07-08 17:28:01 · 286 阅读 · 0 评论 -
Boss
Boss 题意:n个人,m个从属关系,i次操作,T开头代表把两人职位对调,P要求搜索对应人的上司中职位最年轻的解法:应用指针对调,搜索时直接dfs#include <iostream>#include <cstring>#include <stdio.h>#include <stdlib.h>using namespace std;int age[600], last[600],原创 2016-07-08 17:36:35 · 284 阅读 · 0 评论 -
Dangerous Dive
Dangerous Dive题意:给出n,m及m个数,问1~n有哪些没出现 解法:随便,我用了桶#include <iostream>using namespace std;#include <stdio.h>int f[20000] = {0};int main() { int cases = 0, n, m, sum, x; while ((scanf("%d %d", &原创 2016-07-08 17:41:16 · 304 阅读 · 0 评论 -
Triangles
Triangles 题意:圆上给出n个点以及他们与前一个点的距离,求最多有多少组可以组成等边三角形 解法:边相等即弧长相等,直接dp#include <iostream>using namespace std;#include <stdio.h>int a[300000] = {0},b[300000] = {0}, n;int main() { while (scanf("%d",原创 2016-07-08 17:45:09 · 354 阅读 · 0 评论 -
Lines of Containers
Lines of Containers 题意:给出n*m的网格,可以选择行或列交换,问最少多少次能够使得网格变回原序,即1 2 3 …解法:保证每行每列都最多被交换一次,所以直接把交换使得第一行、第一列都为原来序列,再判断网格中是否存在矛盾即可,注意只有一列的情况#include <iostream>using namespace std;#include <stdio.h>#include原创 2016-07-08 17:52:21 · 328 阅读 · 0 评论 -
Buses
Buses题意:读入总长及k,l,分别代表小巴士和大巴士的颜色数,其中小巴长为5,大巴长为10,问用无数量小巴大巴排成长度为n一共有多少种可能解法:矩阵乘法。可以写出递推式,先将n/5,f[1] = k; f[2] = k*k+l; f[i] = f[i-1]*k+f[i-2]*l; 求出f[n]为解,那么就可以用矩阵使得复杂度降到log级别#include <iostream>usin原创 2016-07-08 18:00:45 · 387 阅读 · 0 评论 -
Patches
Patches 题意:轮子上有n个洞,有两种规格的补丁条(无限条),问怎么补使得所用的长度最短 解法:dp#include <iostream>using namespace std;#include <stdio.h>#include <stdlib.h>#include <cstring>int n, m, t1, t2;int f[3000], a[3000];int min(i原创 2016-07-08 18:05:51 · 1118 阅读 · 0 评论 -
Falling Ants
Falling Ants 直接按照题目意思求#include <iostream>using namespace std;#include <stdio.h>int main(){ int n; cin >> n; while(n != 0){ int l, w, h, maxs=0, maxh=0; for(int i =原创 2016-07-09 09:42:01 · 187 阅读 · 0 评论 -
Pattern Locker
Pattern Locker 求 C(n*n,l)l!+C(n*n,l+1)(l+1)!…..+C(n*n,r)*r!#include <iostream>using namespace std;#include <stdio.h>#include <math.h>const long long mo = 10000000000007;long long n, l, r;int main(原创 2016-07-09 09:47:53 · 536 阅读 · 0 评论 -
Two Points Revisited
Two Points Revisited 向量旋转90度#include <iostream>#include <stdio.h>#include <stdlib.h>using namespace std;struct Point{ int x, y; };void Swap(Point& t1, Point& t2) { int temp = t1.x;原创 2016-07-09 09:51:53 · 252 阅读 · 0 评论 -
Watching the Kangaroo
Watching the Kangaroo 题意:给出n段区间(l,r),给出m给位置x,求对于所有(l <= x <= r)区间,求min(x-l,r-x)的最大值。 解法:二分加前缀。对于一个区间,分成两半排序(考虑奇偶),对于x属于左半段的,二分出一个最接近x的右边,假设位置为p,那么在p~n都满足右边大于等于x,那么只有找到p~n左边值的最小值min,答案就是x-min。同理右边#inc原创 2016-07-09 10:02:01 · 266 阅读 · 0 评论 -
Fiasco
Fiasco 题意:给一个按bfs求最短路的代码(这个方法明显有bug),然后给出点和路段,问让你重新分配路径的值使得上诉错误的代码可以得到正确的值解法:先把路径长度排序,再按bfs序从小到大分配#include <iostream>using namespace std;#include <stdio.h>#include <algorithm>#include <cstring>i原创 2016-07-09 10:06:27 · 339 阅读 · 0 评论 -
Dromicpalin Substrings
Dromicpalin Substrings题意:求一个字符串有多少字串是类似回文串的,类似即是字符串通过调整顺序能变成回文串 解法:直接求字符串中出现奇数次的字符的个数,n^2暴力#include <iostream>using namespace std;#include <stdio.h>#include <stdlib.h>#include <string>#include <c原创 2016-07-09 10:10:15 · 232 阅读 · 0 评论 -
A water problem
A water problem . . 高精度取摸 . . 队友代码#include <bits/stdc++.h>struct BigInt { const static int mod = 10000; const static int DLEN = 4; const static int POW = 10000; int a[2500002], l原创 2016-08-16 10:05:55 · 241 阅读 · 0 评论 -
Zhu and 772002
Zhu and 772002 . . 题意:给出n个数,问有多少种取法使得取的数的积为完全平方数。 . . 解法:高斯消元的例题,质数不超过2000只有303个,每个数分解质因数并且模2就成了一个01矩阵,转换成多条式子形如 (k1+k2+k3+…)%2=0,然后对这个矩阵高斯消元,消元后每一行第一个1都是被后面的01所控制,最后结果为2^(n-矩阵不全为0的行数)-1。 . .原创 2016-08-16 10:13:43 · 325 阅读 · 0 评论 -
Danganronpa
Danganronpa . . 这是一道水题,主要是题目描述不清楚。 题意是有一个老师要准备n种礼物,每种礼物有ai个,老师要把这些礼物放到很多个小孩子的座位上,要连续摆放,每个座位放两种礼物,分为普通礼物和神秘礼物,问最多多少个孩子能够满足和他相邻座位的普通礼物不相同。 . . 解法:假设礼物总数为sum,人数不会超过sum/2,然后直接枚举放普通礼物就好,神秘礼物不用管,看最多能放原创 2016-08-16 10:20:37 · 306 阅读 · 0 评论 -
Lweb and String
Lweb and String . . 题意:给一个字符串,字符串中的每一种字母可以转换成任意一种数字,问最终可能的最长严格上升子序列为多长 . . 解法:就是求字符串有多少个不一样的字母 注意一下先计算出字符长度,不要枚举过程中计算,不然会T . . 队友代码#include <cstdio>#include <cstring>char a[100010];int cnt原创 2016-08-16 10:24:39 · 404 阅读 · 0 评论 -
Billionaires
Billionaires . . 题意:给出n个人所在的城市以及个人财富,接下来有k起事件,表示某天某人到达某个城市,问每个城市拥有的财富值最大的天数(比其他所有城市都多)。 . . 解法:用stl直接模拟就行了 . . 队友代码#include <cstdio>#include <map>#include <string>#include <algorithm>#incl原创 2016-08-17 10:36:41 · 408 阅读 · 0 评论 -
Shortest Subchain
Shortest Subchain . . 题意:给出一条链,问第一个点到最后一个点的最短路径,要求走过的边的顺序要和链的顺序相同(即不可以先走后面的边再走前面的边)。 . . 解法:记忆化搜索就好了,记录每一个点最短路径以及从哪里转移过来的。注意的是记录转移不能直接记录从哪个点,因为记录点的话该点在后面的边加入时可能会改变该点前面的路径,所以要把路径投影到链上,记录从链的哪个点转移过来原创 2016-08-17 10:41:20 · 287 阅读 · 0 评论 -
Cipher Message
Cipher Message . . 把字符串相邻相同的字符去掉,直至没法再去除为止,暴力模拟就好了 . .#include <cstdio>#include <cstring>char a[200010];int nextt[200010], pre[200010];int main(){ scanf("%s", a); int n = strlen(a);原创 2016-08-17 10:43:32 · 292 阅读 · 0 评论 -
Sum of Digits
Sum of Digits . . 题意:给出s1、s2,问最小的数使得每位之和为s1,每位平方之和为s2,位数不超过100。 . . 解法:dp,因为不超过100位,用[900][8100]来记录到达当前状态最小的位数,以及同样位数尽量放小的值,先把全部预处理好即可。 . .#include <iostream>#include <stdio.h>#include <stdli原创 2016-08-17 10:55:16 · 599 阅读 · 0 评论 -
Regular Triangles
Regular Triangles . . 这样的Notes也是第一次见 0.0 题意:给出一个正三角形,让你在三角形外找3个点,三角形内找三个点,使得图中总共有不少于9个正三角形。 . . 解法: 如图,一个正六边形以及重心可以贡献8个正三角形(还有两个大三角形),然后只要在正三角形中找多一个小的正三角形就好了原创 2016-08-17 11:07:20 · 301 阅读 · 0 评论 -
POJ 2126 Factoring a Polynomial
Factoring a Polynomial原题:Factoring a Polynomial 题意:问多项式是否能够简化 解法: 1. 若多项式度数为二,利用b^2-4*a*c>=0来判断 2. 若多项式度数大于二,则一定可以化简#include <iostream>using namespace std;int main() { int n; cin >> n;原创 2016-08-07 09:55:50 · 442 阅读 · 0 评论 -
POJ 2127 Greatest Common Increasing Subsequence
Greatest Common Increasing Subsequence原题:Greatest Common Increasing Subsequence 题意:给出两个序列a、b,求最长公共递增子序列。 解法:dp,因为数据范围比较小,我用的是二维,f[i][j]表示a,b到i,j的最长公共递增子序列,然后转移叫好了#include <iostream>using namespace s原创 2016-08-07 10:01:19 · 258 阅读 · 0 评论 -
Less Time, More profit
Less Time, More profit . . 题目是挺裸的网络流,也算例题了吧 源点和商铺连一条流量为收益的边,汇点和工厂连一条流量为工厂投资的花费。因为最大流等于最小割,对于每一个商铺,要么把商铺利益割掉,要么把工厂花费割掉,最后的收益为所有商铺的收益减去最小割就是最大利润。对于时间,我是利用了二分保证最小。 . .#include <stdio.h>#include <st原创 2016-08-29 10:06:19 · 418 阅读 · 0 评论 -
A Boring Question
A Boring Question . . 这题可以找规律(也可以证明这个规律),即m^0+m^1+…+m^n。用等差数列公式就可以求了,由于涉及除法,所以要用逆元。 . .#include <cstdio>const long long mo = 1000000007;long long m, n;long long mypow(long long x, long long n原创 2016-08-24 10:35:34 · 389 阅读 · 0 评论 -
Median
Median . . 题目挺水的。注意给定的序列是有序的,所以其实只有两种情况,要么给定的两段序列无关,要么出现重叠,这两个情况分开弄一下就好了。 . .#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>using namespace std;const int maxn = 10原创 2016-08-29 10:11:42 · 424 阅读 · 0 评论 -
Counting Intersections
Counting Intersections . . 题意:给出平行于坐标轴的线段,保证无重叠,端点相同的情况,问有多少交点。 . . 解法:首先我把数离散化,那么数的大小不超过4*10^5,这样就可以用树状数组。首先把平行于x、y轴的分开存。对于垂直于x轴的按x坐标排序,对于垂直于y轴的按x坐标左端点进行排序。然后扫描垂直x坐标轴的线段,可以很快找到所以垂直y轴的而且左端点在该x坐标左原创 2016-08-29 10:21:31 · 405 阅读 · 0 评论 -
Headstrong Student
Headstrong Student . . 水题,对于一个分数,要求求出其循环节的长度以及小数点后到循环节有多少位小数。因为数比较小,直接记忆化余数出现的位置就好了。 . .#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int maxn=1e6+10;int vis[ma原创 2016-08-29 10:26:07 · 365 阅读 · 0 评论 -
Dig or Climb
Dig or Climb . . 题意:给出一些山体,人可以用Vw的速度在表面行走,也可以用Vc的速度在山中严格水平的隧道通过,问最短的时间到达终点。 . . 解法:首先要注意的是在水平的线上是不能打隧道的。我用了两个数组记录:一个是哪些点可以往后面的点进行挖隧道转移,显然只要不是山顶,即该点高度低于下一个点的高度(严格小于),可以挖隧道。一个是哪些点可以通过打隧道转移,明显对于该点原创 2016-08-29 10:35:43 · 475 阅读 · 0 评论 -
POJ 2128 Highways
Highways原题:Highways 题意:高速公路上有n个站,n-1条单向路径,新来的市长希望加两条路满足任意两个城市都能相互到达,并使得距离最短 解法:看样例数据都看得出来,头尾延伸一条反向路,并使得两条路径重复覆盖的距离最小,即找一条最短的路#include<iostream>using namespace std;int main(){ int n; cin >>原创 2016-08-07 19:21:22 · 247 阅读 · 4 评论 -
Aztec Pyramid
Aztec Pyramid 题意:给n个木块堆放,最高能堆多少层,要求除了地面的木块其他木块满足该木块下一层的正下方已经其正下方的上下左右都有木块。 解法:直接按照最优的方案堆积#include <iostream>#include <stdio.h>using namespace std; int a[10000010],sum[10000010]; int main() {原创 2016-08-08 09:35:36 · 478 阅读 · 0 评论 -
Battleship
Battleship题意:你有一艘四格的船,两艘三格的船,三艘两格的船以及四艘一格的船,要求放在一格10*10的网格中,使得彼此之间不相邻,而且一定要把只为100的格子覆盖解法:暴力搜索#include <iostream>using namespace std;#include <stdio.h>char map[20][20];int maxx, maxy, t;bool flag =原创 2016-08-08 09:39:32 · 770 阅读 · 0 评论 -
Deepest Station
Deepest Station 题意:三维空间给两个点,问能否利用两条与地面夹角为45度的扶梯到达。 解法:其实可以利用投影,且45度的话底和高一样长,然后直接算就好。#include <iostream>using namespace std;#include <stdio.h>#include <math.h>#include <stdlib.h>double sqr(double原创 2016-08-08 09:45:41 · 205 阅读 · 0 评论 -
Electricity
Electricity 题意:两种插头的多种排插,插头只能按照如图所示的方法连接,问最多有多少个可以使用(即还没被插上)的A型插座 解法:直接贪心就好,分别记录A,B型的插头数目,并把数量多的尽量安排在前面就行了#include <iostream>using namespace std;#include <stdio.h>#include <stdlib.h>#include <alg原创 2016-08-08 09:50:32 · 251 阅读 · 0 评论 -
Final Standings
Final Standings 题意:有n个车手在比赛,其中前k个车手的总得分为p,且只有d个不同的分数,问最终n位车手的排名 解法:贪心,k以后的选手可以为0,所以直接贪心就好#include <iostream>using namespace std;#include <stdio.h>int f[1000];int main() { freopen("final.in","r原创 2016-08-08 09:55:29 · 392 阅读 · 0 评论