POJ 1925 别人家的代码是厉害啊~
2014-03-23 00:48
218 查看
TTTT,T死我了,这么水的DP。。。。
原来是。。。!(看了别人家的代码才知道!!而且看了好多遍。。)坐标乘的时候会超INT 啊。。
好吧。。。
这题思路:
首先,蜘蛛侠Y坐标不会变。
然后从一个点通过一个柱子到另一个点,就是 x 坐标对柱子做一次轴对称。
枚举的时候,从每个柱子哪里开始枚举,直到前面的点不能转移到该柱子。
从别人家的代码。。。还学到。。。要给数组赋值为 0x3f3f3f3f 的时候可以直接 memset(a,0x3f,sizeof(a))
原来是。。。!(看了别人家的代码才知道!!而且看了好多遍。。)坐标乘的时候会超INT 啊。。
好吧。。。
这题思路:
首先,蜘蛛侠Y坐标不会变。
然后从一个点通过一个柱子到另一个点,就是 x 坐标对柱子做一次轴对称。
枚举的时候,从每个柱子哪里开始枚举,直到前面的点不能转移到该柱子。
从别人家的代码。。。还学到。。。要给数组赋值为 0x3f3f3f3f 的时候可以直接 memset(a,0x3f,sizeof(a))
#include <stdio.h> #include <iostream> #include <queue> #include <algorithm> #include <map> #include <vector> #include <cmath> #include <string.h> #include <stdlib.h> #include <time.h> #include <fstream> #include <set> #include <stack> using namespace std; #define READ freopen("acm.in","r",stdin) #define WRITE freopen("acm.out","w",stdout) #define ll long long #define ull unsigned long long #define PII pair<int,int> #define PDI pair<double,int> #define PDD pair<double,double> #define MII map<int,int>::iterator #define fst first #define sec second #define MS(x,d) memset(x,d,sizeof(x)) #define INF 0x3f3f3f3f #define ALL(x) x.begin(),x.end() #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define ROOT 0,n-1,1 #define PB push_back #define FOR(a,b,c) for(int a=b;a<c;a++) #define MOD 1000000007 #define keyTree (ch[ ch[root][1] ][0]) #define MAX 1111111 int dp[MAX]; ll X[10000],Y[10000]; ll y; int main() { int cas; READ; scanf("%d",&cas); while(cas--) { //fill(dp,dp+MAX,INF); MS(dp,0x3f); int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lld%lld",&X[i],&Y[i]); y=Y[0]; dp[X[0]]=0; for(int i=1;i<n;i++) { for(ll x=X[i]-1;x>=X[0];x--) { ll dx=x-X[i]; ll dy=y-Y[i]; if(dx*dx+dy*dy>Y[i]*Y[i]) break; if(dp[x]==INF) continue; int tar=2*X[i]-x; if(tar<X[n-1]) dp[tar]=min(dp[tar],dp[x]+1); else dp[X[n-1]]=min(dp[X[n-1]],dp[x]+1); } } if(dp[X[n-1]]==INF) puts("-1"); else cout<<dp[X[n-1]]<<endl; } return 0; }
相关文章推荐
- POJ 3007 别人家的质数都这么厉害!!
- POJ 2255(理解别人的代码的)
- poj 3908 还是能力不够,总得看别人代码后才幡然醒悟!
- 【POJ2796】代码,非原创,参考的别人的文章
- 转一个别人写的优秀代码 Octal Fractions(转自poj)
- 【poj 1925】Spiderman 题意&题解&代码(C++)
- git给别人提交代码
- 7,26改的别人代码
- java获取客户端ip 及通过ip获取mac地址后台代码(借鉴别人)
- Github上fork了别人的项目之后如何同步代码
- POJ代码提交器 QNetworkAccessManager post get
- 如何快速的看懂别人的代码
- 阿牛的EOF牛肉串(参考别人的思路写的代码)
- POJ 1035 代码+具体的目光
- poj 2106 Boolean Expressions 课本代码
- POJ_1251 (Java代码)
- 如何阅读别人的代码
- 当年写的俄罗斯方块(现在更喜欢研究别人的代码)
- android ListView下拉刷新(代码是别人的,但是本人写了很多注释,并准备好好分析下原因)
- 贪吃蛇完整代码,为什么别人的代码,我抄下来就出错,请高手们指点一下,我的蛇不会走