- 博客(462)
- 收藏
- 关注
原创 poj 2556 Edge 向量旋转
//poj 2556//sep9#includeusing namespace std;char s[256];int main(){ while(scanf("%s",&s)==1){ int px=300,py=420; int x=310,y=420; puts("300 420 moveto\n310 420 lineto"); for(int i=0;s[
2015-07-05 23:02:00 1131
原创 poj 3105 Expectation 按位统计
题意:给n,求sum(i^j)/(n^2),0分析:暴力n^2算法肯定超时。这是logn按位统计算法:按位先算出0出现的个数x,则1出现的个数为n-x,再算每位对和的贡献。代码://poj 3105//sep9#include using namespace std;int main(){ int cases; scanf("%d",&cases); whil
2015-07-05 21:27:37 878
原创 poj 2660 War on Weather 计算几何
//poj 2660 //sep9#include #include using namespace std;const double pi=acos(-1.0);const double radius=20000.0/pi;struct P{ double x,y,z,angle;}satellite[128];double dist(double x,double y
2015-07-05 18:41:13 714
原创 poj 2945 Find the Clones trie树的简单应用
题意:给n个长m的字符串,统计他们的出现频率,输出出现1次的有几种,出现2次的有几种...出现n次的有几种。n分析:也可以用排序,map水的,但还是写个trie树也不麻烦,trie树我就得就是针对字符串的hash表,效率如果数据大点是比暴力解法高很多的,另外写的时候不小心把index定义成char,n代码://poj 2945//sep9#include using na
2015-07-05 12:16:59 657
原创 poj 2955 Brackets dp简单题
//poj 2955//sep9#include using namespace std;char s[128];int dp[128][128];int n;int rec(int l,int r){ if(dp[l][r]!=-1) return dp[l][r]; if(l==r) return dp[l][r]=0; if(l+1==r){ if(s[l
2015-07-05 10:44:44 660
原创 poj 3071 Football 概率dp
题意:有2*n只队伍参加n论的淘汰赛,给出任意两只队伍交战的各自的胜率,求最后剩下概率最高的队伍。分析:概率dp,dp[i][j]表示第i轮结束后队伍j还在场上的概率,dp[i][j]=dp[i-1][j]*sum(dp[i-1][k]p[j][k])(1>i==(k-1)>>i&&(j-1)>>(i-1)!=(k-1)>>(i-1),把每个队的id用二进制写出来画画图就知道为什么这样
2015-07-04 00:16:56 1243
原创 poj 2780 Linearity 最多共线点经典问题
题意:给n个点,其中最多有多少点共线(n分析:这是一个经典问题,朴素n^3解法:枚举n^2条直线,判断每条直线与多少点相交,复杂度n^3。明显会超时。这是n^2logn的解法:枚举每个点,对某个点与其他点连的n条直线按斜率排序,设这些直线中斜率相同的直线有k条,则k更新答案。这里想着重说一下斜率的问题,网上很多代码都是直接算斜率的,但计算几何的题目不推荐用斜率,最好用叉积代替有关斜率的
2015-07-03 20:36:36 1809 1
原创 poj 2193 Lenny's Lucky Lotto Lists 简单dp
//poj 2193//sep9#include using namespace std;typedef __int64 INT;INT dp[16][2048];int n,m;int main(){ int cases,t=0; scanf("%d",&cases); while(cases--){ scanf("%d%d",&n,&m); memset(dp,0
2015-07-03 01:19:03 1367
原创 poj 4014 Dice 贪心
//poj 4014//sep9#include #include using namespace std;int n;struct DICE{ int ids; int num; int a[128];}d[1024];int cmp1(DICE x,DICE y){ return x.num<y.num;}int cmp2(DICE x,DICE y){
2015-07-02 22:29:59 844
原创 poj 4016 Flat 水题
#include using namespace std;int main(){ int n,c,area=0,bed_area=0,bal_area=0; scanf("%d%d",&n,&c); while(n--){ int x; char s[16]; scanf("%d%s",&x,s); area+=x; if(strcmp(s,"bedroom")=
2015-07-02 11:31:31 928
原创 poj 1694 An Old Stone Game 树形dp
//poj 1694//sep9#include #include using namespace std;const int maxN=256;int n;int tree[maxN][maxN];int ans[maxN];int cmp(int a,int b){ return a>b;}int dfs(int u){ int tmp[maxN],t=0; i
2015-07-02 10:57:48 864
原创 poj 1021 2D-Nim 模拟
题意:给两个平面,每个平面上有一些点,相邻的点可构成点集,为两个平面内的点集是够都对应相似。两个点集相似是指经过对称或旋转或平移后相等。分析:直接模拟判断。代码://poj 1021//sep9#include #include #include using namespace std;int w,h,n;int g[128][128];int vis[128]
2015-07-01 12:28:19 914
原创 poj 2960 S-Nim nim博弈grundy值计算法入门
题意:给k堆石子,两人轮流向某一堆中拿,拿的个数要从给定的一个集合中取,没石子拿的输,问先手必胜还是必败。分析:grundy值计算法的入门题。代码://poj 2960//sep9#include #include using namespace std;int s[128];int grundy[10024];int maxx;int num;int get
2015-07-01 10:13:24 959
原创 poj 1671 Rhyme Schemes 第二类Stirling数
题意:求s(n,0)+s(n,1)+...s(n,n),s(i,j)为第二类Stirling数。分析:有递推公式s(p,k)=(p-1)*s(p-1,k)+s(p-1,k-1) ,1代码://poj 1671//sep9#includeusing namespace std;double s[64][64];double sum[64];int main(){
2015-07-01 09:33:02 829
原创 poj 3154 Graveyard 贪心
//poj 3154//sep9#include #include using namespace std;double a[2048];double b[2048];int main(){ int n,m; while(scanf("%d%d",&n,&m)==2){ for(int i=0;i<n;++i) a[i]=i*(10000.0/n); for(i
2015-06-30 23:40:42 872
原创 poj 2683 Ohgas' Fortune 利率计算
水题。代码://poj 2683//sep9#include using namespace std;int main(){ int cases; scanf("%d",&cases); while(cases--){ int fund,year,op,ans=-1; scanf("%d%d%d",&fund,&year,&op); while(op--){
2015-06-30 21:48:38 864
原创 poj 3307 Smart Sister 打表解因子生成数问题
题意:给i,求由仅以2,3,5,7为因子的数中第i个是多少。分析:打表。代码://poj 3307//sep9#include using namespace std;typedef unsigned __int64 INT;const int maxL=66062;INT a[maxL+10];INT min4(INT a,INT b,INT c,INT d)
2015-06-30 21:04:52 807
原创 poj 3241 Object Clustering 曼哈顿最小生成树
题意: 平面上有n个点,现在把他们分成k个集合,使得每个集合中的每个点都至少有一个本集合的点之间的曼哈顿距离不大于X,求最小的X。分析: 转化为求n个点生成完全图的最小生成树的第k大边。接下来有几个重点。1)根据莫队算法,由于边权是点的曼哈顿距离,每个点只需要跟周围8个方向中每个方向最近的点连边,这样算出的图与用完全图算出的最小生成树一样,涉及的边却大大
2015-06-29 10:28:55 1432
原创 poj 3103 Cutting a Block 模拟水题
水题#include using namespace std;int main(){ int x,y,z,n; scanf("%d%d%d%d",&x,&y,&z,&n); for(int i=0;i<n;++i) printf("0 0 %.8lf %d %d %.8lf\n",(z*1.0/n)*i,x,y,(z*1.0/n)*(i+1)); return 0; }
2015-06-27 13:57:35 956
原创 poj 2917 Diophantus of Alexandria 因数分解解1/x+1/y=1/n
题意:给定n,求丢番图方程1/x+1/y=1/n(x分析:设x=n+a,y=n+b,化简可得n^2=a*b.设n^2的因子个数为p,n^2的所有因子中除n外都是成队出现的,故方程解数为(p+1)/2。代码://poj 2917//sep9#include using namespace std;int num[64];int main(){ int cases,
2015-06-26 10:03:09 1483
原创 poj 3221 Diamond Puzzle 反向bfs
分析:简单的bfs,但要注意因为输入cases很多,对每个初始状态都搜一遍会超时,其实可以从终止状态反向搜一遍,对搜到的每个状态打表存下即可。代码://poj 3221//sep9#include #include using namespace std;int n;int fac[]={1,1,2,6,24,120,720,5040,40320}; int vis[1
2015-06-25 19:33:50 826
原创 poj 3681 Finding the Rectangle 尺取法解最小矩形覆盖问题
题意:平面上有n个点,现在要求一个面积最小的矩形能完全覆盖其中的m个点(边界不算)。分析:求满足某个性质的最小区间的问题尺取法比二分还要高效,这题可以在x上暴力枚举,在y上用尺取法(在x,y上都用尺取法是不对的)。代码://poj 3681//sep9#include #include using namespace std;int n,m,ans;struct P
2015-06-25 15:47:43 1504
原创 poj 3869 Headshot 全概率公式
//poj 3869//sep9#include using namespace std;char s[128];int main(){ scanf("%s",s); int l=strlen(s); int a=0,b=0,c=0,d=0; for(int i=0;i<l;++i) if(s[i]=='1') ++c; d=l; for(int i=0;i<l
2015-06-24 06:24:54 1436
原创 poj 3537 Crosses and Crosses 博弈论之grundy值
题意:给1*的格子,轮流在上面叉叉,最先画得3个连续叉叉的赢,问先手必胜还是必败。分析:求状态的grundy值(也就是sg值),具体怎么求详见代码,为什么这么求要自己想的,只可意会(别人都说去看game theory,呵呵)。代码://poj 3537//sep9#include #include using namespace std;int grundy[2048
2015-06-24 01:03:38 1674
原创 poj 1868 Antiarithmetic? 判断序列中是否有等差子序列
#includeusing namespace std;const int maxN=10024;int n,vis[maxN],a[maxN];bool find(){ memset(vis,-1,sizeof(vis)); for(int i=0;i<n;++i){ for(int j=0;j<i;++j){ int t=2*a[i]-a[j]; if(t>=0
2015-06-22 16:30:11 1023
原创 poj 2751 双机调度问题Johnson算法(贪心)
题意:2台机器,n件任务,每件任务必须先在S1上做,再在S2上做。任务之间先做后做任意。求最早的完工时间。分析: 这是一个经典问题:2台机器的情况下有多项式算法(Johnson算法),3台或以上的机器是NP-hard的。Johnson算法思想就是贪心,时间复杂度是O(nlogn) 。Johnson算法: (1) 把作业按工序加工时间分成两个子集,第一个集合中在S1上做
2015-06-22 15:43:36 3621
原创 poj 1060 Modular multiplication of polynomials 除数是大数的高精度除法
题意:给f(x),g(x),h(x),求(f(x)*g(x))%h(x)。分析:难点是如何做除数是大数的高精度除法,如果除数不是大数只有被除数是大数的话4,5行代码就可以写除法部分了(http://blog.csdn.net/sepnine/article/details/46562599)。代码://poj 1060//sep9#include using namesp
2015-06-21 23:29:58 775
原创 poj 2305 Basic remains 高精度取余
题意:裸的高精度取余。分析:http://blog.csdn.net/sepnine/article/details/44092055有poj 1220任意进制转换的代码,这题用到其中的一部分,可作对比。代码://poj 2305//sep9#include using namespace std;int b,m;char s1[1024],s2[16],ans[16
2015-06-19 16:11:36 1147
原创 poj 1270 Following Orders 枚举排列
题意:给一个字符集和一些字符之间的小于关系,求字符集上的所有可能排列。分析:暴力枚举可以分为枚举子集,枚举排列,枚举组合,这题是个简单的枚举排列,枚举过程中用小于关系剪枝即可。代码://poj 1270//sep9#include #include using namespace std;char vars[64],constraint[256],ans[64];i
2015-06-16 20:30:48 774
原创 poj 1905 Expanding Rods 二分解方程
题意: 中已知L,S解h。分析:两个方程两个未知数,理论是可解的。解起来有困难,可用二分的方法。代码:#include #include using namespace std;int main(){ double l,n,c,s,r; while(scanf("%lf%lf%lf",&l,&n,&c)==3){ if(l<0) break;
2015-06-15 12:23:57 714
原创 poj 1166 The Clocks 记录路径的广搜
题意:给9个时钟的初始状态,和一些对某几个钟的操作,求最少经过几步能到目标状态(全指向12点)。分析:明显的广搜,但实现起来的细节要注意:1.因为要记录路径,所以要在整个程序执行过程中扩展出的节点在输出路径前不能销毁, 故采用静态内存分配的方法(开node[600000],用get_node()创建节点。2.queue比queue要多花1别的时间。//poj 1166//sep9
2015-06-05 17:26:55 718
原创 poj 3696 The Luckiest number 欧拉函数在解a^x=1modm的应用
题意:给一个L,求长度最小的全8数满足该数是L的倍数。分析:转化为求方程a^x==1modm。之后就是各种数学论证了。代码://poj 3696//sep9#include #include using namespace std;typedef long long ll;ll L;ll factor[65536];ll mul(ll x,ll y,ll p)
2015-06-04 17:43:21 1137
原创 poj 2480 Longge's problem 积性函数性质+欧拉函数
题意:求f(n)=∑gcd(i, N) 1分析:f(n)是积性的数论上有证明,且f(n)=sigma{1代码://poj 2480//sep9/*f(pi^ai) = Φ(pi^ai)+pi*Φ(pi^(ai-1))+pi^2*Φ(pi^(ai-2))+...+pi^(ai-1)* Φ(pi)+ pi^ai *Φ(1) = pi^(ai-1)*(pi-1) +
2015-06-03 00:11:13 1452
原创 poj 2313 Sequence 贪心
#include using namespace std;int n;int a[128],b[128];int main(){ scanf("%d",&n); for(int i=0;i<n;++i) scanf("%d",&a[i]); b[0]=a[0]; for(int i=1;i<n-1;++i){ if(a[i]>b[i-1]&&a[i]>a[i+1])
2015-05-28 17:02:45 1012
原创 poj 1324 Holedox Moving A*算法对bfs的优化
题意:迷宫里有一条贪食蛇,求它的蛇头到迷宫左上角最少要多少步。分析:关键是将蛇的状态压缩编码,然后bfs,超时就改A*,这题有类似最短路径的性质,A*发现节点重复后不需要更新直接舍弃即可。代码://poj 1324//sep9#include #include #include using namespace std;struct state{ int x[1
2015-05-27 19:12:32 763
原创 poj 2110 Mountain Walking 枚举+bfs
题意:给一个n*n的矩阵,要从左上角走到右下角,使经过数字的最大数与最小数的差最小。分析:一开始想到了二分这个差,然后判断是否存在路径,每次只知道差的话深搜每次搜索要记录沿途的最大值和最小值会tle,广搜的话如果节点只记录x,y坐标,搜索中存在要重新访问以前访问过节点的情况,比如一开始(1,1)->(1,2)->(2,2),如果(2,1)这个点的值更合适,最优访问路径(1,1)->(2
2015-05-21 15:59:10 1086
原创 poj 1171 Letter Game 字符串处理或字符串背包
#include using namespace std;char s[16];int cnt[256];int tot[256];int m[256];struct DICT{ char words[10]; int len,val;}dic[40010];int tovalue(char ch[]){ int sum=0; for(int i=0;ch[i]!='
2015-05-20 13:47:55 1106
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人