POJ 3034 Whac-a-Mole(DP)
理解了题意之后,这个题感觉状态转移还是挺好想的,实现起来确实有点繁琐,代码能力还有待加强,经过很长时间才发现bug。注意坐标可能是负的。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int dp[][][];
bool o[][][];
int n,ans,d;
int gcd(int a,int b)
{
return b == ?a:gcd(b,a%b);
}
int fun(int t,int x,int y,int tx,int ty,int ax,int ay)
{
int temp = ;
while(x != ax||y != ay)//开始这里写成&&
{
if(o[t+][x][y])
temp ++;
x += tx;
y += ty;
}
return temp+o[t+][x][y];
}
void judge(int t,int x,int y)
{
int i,j,g;
for(i = x-d;i <= x+d;i ++)
{
for(j = y-d;j <= y+d;j ++)
{
if((i-x)*(i-x)+(j-y)*(j-y) > d*d) continue;
if(i < ||j < ) continue;
if(i > n+||j > n+) continue;
g = gcd(abs(i-x),abs(j-y));
if(g == ) g = ;
int tx,ty;
tx = (i-x)/g;
ty = (j-y)/g;
dp[t+][i][j] = max(dp[t+][i][j],dp[t][x][y]+fun(t,x,y,tx,ty,i,j));
ans = max(dp[t+][i][j],ans);
}
}
}
int main()
{
int m,i,j,k,y,x,t;
while(scanf("%d%d%d",&n,&d,&m)!=EOF)
{
if(n == &&d == &&m == ) break;
memset(dp,,sizeof(dp));
memset(o,,sizeof(o));
for(i = ; i <= m; i ++)
{
scanf("%d%d%d",&x,&y,&t);
o[t][x+][y+] = ;
}
ans = ;
for(i = ; i <= ; i ++)
{
for(j = ; j < n+; j ++)
{
for(k = ; k < n+; k ++)
{
judge(i,j,k);
}
}
}
printf("%d\n",ans);
}
return ;
}
POJ 3034 Whac-a-Mole(DP)的更多相关文章
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- poj 3311(状态压缩DP)
poj 3311(状态压缩DP) 题意:一个人送披萨从原点出发,每次不超过10个地方,每个地方可以重复走,给出这些地方之间的时间,求送完披萨回到原点的最小时间. 解析:类似TSP问题,但是每个点可以 ...
- poj 1185(状态压缩DP)
poj 1185(状态压缩DP) 题意:在一个N*M的矩阵中,‘H'表示不能放大炮,’P'表示可以放大炮,大炮能攻击到沿横向左右各两格,沿纵向上下各两格,现在要放尽可能多的大炮使得,大炮之间不能相互 ...
- poj 3254(状态压缩DP)
poj 3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...
- poj 2324 Anniversary party(树形DP)
/*poj 2324 Anniversary party(树形DP) ---用dp[i][1]表示以i为根的子树节点i要去的最大欢乐值,用dp[i][0]表示以i为根节点的子树i不去时的最大欢乐值, ...
- (中等) POJ 3034 Whac-a-Mole,DP。
Description While visiting a traveling fun fair you suddenly have an urge to break the high score in ...
- POJ 3034 Whac-a-Mole(DP)
题目链接 题意 : 在一个二维直角坐标系中,有n×n个洞,每个洞的坐标为(x,y), 0 ≤ x, y < n,给你一把锤子可以打到地鼠,最开始的时候,你可以把锤子放在任何地方,如果你上一秒在( ...
- poj 1141 Brackets Sequence (区间dp)
题目链接:http://poj.org/problem?id=1141 题解:求已知子串最短的括号完备的全序列 代码: #include<iostream> #include<cst ...
- POJ 3034 Whac-a-Mole
Whac-a-Mole Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3070 Accepted: 922 Descriptio ...
随机推荐
- cobbler部署机器的默认密码
修改cobbler的默认密码: 用 openssl 生成一串密码后加入到 cobbler 的配置文件(/etc/cobbler/settings)里,替换 default_password_crypt ...
- Java单链表、双端链表、有序链表实现
单链表: insertFirst:在表头插入一个新的链接点,时间复杂度为O(1) deleteFirst:删除表头的链接点,时间复杂度为O(1) 有了这两个方法,就可以用单链表来实现一个栈了,见htt ...
- 【leetcode】Letter Combinations of a Phone Number
Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations ...
- eclipse字体的设置
eclipse的默认字体太小,所以设置的大一些比较清楚,方法很简单,单击菜单栏的"Window"选择"Preferences",如下图: 然后左侧依次选择Gen ...
- Java for LeetCode 048 Rotate Image
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- codeforces B. Jeff and Periods 解题报告
题目链接:http://codeforces.com/problemset/problem/352/B 题目意思:给出一个长度为n的序列 a1, a2, ..., an(序号i,1 <= i ...
- Maven的安装、配置及使用入门
Maven的安装.配置及使用入门 本书代码下载 大家可以从我的网站下载本书的代码:http://www.juvenxu.com/mvn-in-action/,也可以通过我的网站与我取得联系,欢迎大家与 ...
- Linux下RPM、tar.gz、DEB格式软件包的区别
初接解Linux的朋友一定对软件的安装特别头疼,同样都是for Linux,但RPM.tar.gz.DEB包还是有很大区别的,这种区别很有可能使你的安装过程进行不下去.那我们应该下载什么格式的包呢 ...
- Popular Cows(codevs 2186)
题意: 有N(N<=10000)头牛,每头牛都想成为most poluler的牛,给出M(M<=50000)个关系,如(1,2)代表1欢迎2,关系可以传递,但是不可以相互,即1欢迎2不代表 ...
- 爱改名的小融 2(codevs 3149)
3149 爱改名的小融 2 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description Wikioi上有个人 ...