POJ 3034 (dp) 锤子尼玛能在棋盘外面。。出题不带这么坑的
来源:互联网 发布:关键词优化排名 编辑:程序博客网 时间:2024/05/16 13:45
打地鼠游戏,棋盘是 n*n 的,给你所有地鼠的位置和出现时间,锤子只能走直线,但是只能打到整数点上的地鼠。
GCD可以帮助解决两点之间连线有几个点是整数点的问题。
只是我的代码处理这个问题的时候有点长。。真的有点长。。。
剩下的dp 很显然啊。。
dp[t][x][y] 表示 t 时间锤子在 x , y 的时候最多砸几个。。。
这个题啊。坑在。。。你怎么能把锤子放在外面还能算距离呢!!!!
╮(╯▽╰)╭
#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 uint unsigned int#define PII pair<int,int>#define PDD pair<double,double>#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 PB push_back#define MOD 99991#define MAX 1111int dp[20][50][50];int b[20][50][50];int n,d,m;bool used[30][30];int dir[4][2]={0,1,1,0,-1,0,0,-1};int main(){ READ; while(scanf("%d%d%d",&n,&d,&m)) { if(!n&&!m&&!d) return 0; MS(dp,0),MS(b,0); int maxt=-1; for(int i=0;i<m;i++) { int x,y,t; scanf("%d%d%d",&x,&y,&t); b[t][x+d][y+d]=1; maxt=max(maxt,t); } for(int t=1;t<=maxt;t++) { for(int x=0;x<n+2*d;x++) { for(int y=0;y<n+2*d;y++) { for(int tx=0;tx<n+2*d;tx++) { for(int ty=0;ty<n+2*d;ty++) { if(tx==x&&ty==y)// 相同点。。 { dp[t][x][y]=max(dp[t][x][y],dp[t-1][x][y]+b[t][x][y]); continue; } int dx=abs(tx-x),dy=abs(ty-y); if(dx*dx+dy*dy>d*d) continue; int g=__gcd(dx,dy); int ddx,ddy; if(!g)// 某点与目标点是水平或者竖直直线 { if(!dx) ddx=0,ddy=1; else ddx=1,ddy=0; } else ddx=dx/g,ddy=dy/g;///正常情况 单次前进距离 int dix,diy; if(dx) dix=(x-tx)/dx;//方向 if(dy) diy=(y-ty)/dy; int tot=0; int ttx=tx,tty=ty; while(ttx!=x||tty!=y) { tot+=b[t][ttx][tty]; ttx+=dix*ddx; tty+=diy*ddy; } tot+=b[t][ttx][tty]; dp[t][x][y]=max(dp[t][x][y],dp[t-1][tx][ty]+tot); } } } } } int ans=-1; for(int i=0;i<n+2*d;i++) for(int j=0;j<n+2*d;j++) ans=max(ans,dp[maxt][i][j]); cout<<ans<<endl; } return 0;}
0 0
- POJ 3034 (dp) 锤子尼玛能在棋盘外面。。出题不带这么坑的
- 为什么学习C语言这么久,看的懂代码,做不出题,写不出来项目?
- poj 1191 棋盘分割(DP)
- POJ 1191 棋盘分割 (DP)
- 【POJ 1191】 棋盘分割(DP)
- 这么好的扫描仪怎么能不大力推荐呢
- poj 1191 棋盘分割 DP
- POJ 1191 棋盘分割 DP
- poj-1191- 棋盘分割dp
- POJ 1191 棋盘分割 DP
- poj - 1191 - 棋盘分割(dp)
- POJ 1191 棋盘分割(DP)
- poj 1191 棋盘分割(dp)
- HDOJ 2067 小兔的棋盘(棋盘dp)
- 经典问题六.(二维的区间dp)棋盘分割 poj 1191
- 在提高班外面的日子
- JQuery实现点击div里面的元素能触发点击事件,但是不触发外面的div的点击事件
- poj 2486 Apple Tree (带回溯的树形dp)
- Socket编程原理
- eclipse
- UVA 11400 Lighting System Design(贪心+DP)
- ArcGIS 10.1 for Server 在windows下的安装
- 课题实验(一)
- POJ 3034 (dp) 锤子尼玛能在棋盘外面。。出题不带这么坑的
- 一种对图象进行局部放大的有效方法
- 关于Android的一些设计
- POJ 2586 Y2K Accounting Bug(贪心)
- 大学生创业指导——A Student’s Guide to Startups
- eclipse下调试图片上传,不能立即显示的问题
- Annotation注解 (一)
- ArcGIS 10.1 for Server安装教程系列—— Linux下的单机安装
- 压缩跟踪Compressive Tracking