↓ Skip to main content
  1. Posts/

codeforces 30 C. Shooting Gallery

·425 words·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

http://codeforces.com/contest/30/problem/C 题意:给出n个target在一个二维平面上。给出每个target的坐标,出现的时间,以及击中的概率。target出现之后就会瞬间消失,枪移动的单位速度为1,射击不需要时间。问能击中的target的最大期望是多少。

思路:路径dp。。。按照时间升序排列。 dp[i]表示到第i个target出现的时候的期望。

代码实现
 1/* ***********************************************
 2Author :111qqz
 3Created Time :2015年12月29日 星期二 18时14分45秒
 4File Name :code/cf/problem/30C.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=1E3+7;
34int n;
35double dp[N];
36int dblcmp(double d)
37{
38    return d<-eps?-1:d>eps;
39}
40struct point
41{
42    int x,y,t;
43    double p;
44
45    void input()
46    {
47	scanf("%d %d %d",&x,&y,&t);
48	scanf("%lf",&p);
49    }
50
51    double dis(point p)
52    {
53	return sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));
54    }
55
56    bool operator <(point p)const
57    {
58	return t<p.t;
59    }
60}p[N];
61int main()
62{
63	#ifndef  ONLINE_JUDGE
64	freopen("code/in.txt","r",stdin);
65  #endif
66	cin>>n;
67	for ( int i = 1 ; i <= n ; i++) p[i].input();
68
69	sort(p+1,p+n+1);
70
71	double ans=0;
72	for ( int i = 1 ; i <= n ; i++)
73	{
74	    dp[i] = p[i].p;
75	    for ( int j = 1 ; j < i ; j++)
76	    {
77		if (dblcmp(p[i].dis(p[j])-p[i].t+p[j].t)<=0)
78		    dp[i] = max(dp[i],dp[j]+p[i].p);
79	    }
80	    ans = max(dp[i],ans);
81	}
82	printf("%.10f\n",ans);
83
84  #ifndef ONLINE_JUDGE
85  fclose(stdin);
86  #endif
87    return 0;
88}

Related

codeforces #327 A. Flipping Game

·418 words·1 min
http://codeforces.com/contest/327/problem/A 题意:给定一段序列,只由0,1组成。要求选一段非空区间,做翻转操作(0变1,1变0),问变完之后1最多能有多少。 思路:最后的1个个数=初始的1的个数+变换区间的0的个数-变换区间的1的个数。初始的是常数。那么我们只要找到某一个区间内,0的个数-1的个数有最大值即可。如果a[i]==0的时候令b[i]=1,否则b[i]=0,那就是经典了最大连续区间和的问题了。dp的思想o(n)可以解决。

codeforces 456 C. Boredom

·457 words·1 min
http://codeforces.com/contest/456/problem/C 题意:给出n(1E5)个数(1E5),每次可以选一个数a[k]并删掉a[k],a[k]-1,a[k]+1得到a[k]分,问最多能得到的分数。 思路:裸dp.f[i]表示选到数i的时候能达到的最大分数。开一个计数数组cnt[x]表示数字x出现的次数。那么显然有f[0]=0,f[1]=cnt[1],f[i(i>=2)] = max(f[i-1],f[i-2]+f[i]*cnt[i]);答案为f[max(a[i])],注意要开long long

zoj 3634 Bounty hunter(dp,已经想明白)

·846 words·2 mins
M - Bounty hunter **Time Limit:**5000MS **Memory Limit:**65536KB 64bit IO Format:%lld & %llu Submit Status Description Bounty hunter is a hero who always moves along cities to earn money by his power. One day he decides to N cities one by one At the beginning ,Bounty hunter has X money and Y points of Attack force. At day 1, he will goes to city 1, then city 2 at day 2, city 3 at day 3, … At last ,he goes to city N at day N and leaves it at day N+1. In each city, he can increase his attack force by money and earn some money by accepting a task. In the city i, it costs him ai money to increase one point of attack force. And he can gets bi*yi money after finishing the task in city i while yi is his attack force after his increasing at city i.

hdu 5481||bestcoder #57 div 2 C Desiderium (概率)

·1140 words·3 mins
Desiderium # **Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 427 Accepted Submission(s): 167 ** Problem Description There is a set of intervals, the size of this set is n. If we select a subset of this set with equal probability, how many the expected length of intervals’ union of this subset is? We assume that the length of empty set’s union is 0, and we want the answer multiply 2n modulo 109+7.