2013长沙regional部分题解(hdu4791-4801)

1001:

签到题,二分一下即可

代码:

 1 #include <set>
 2 #include <map>
 3 #include <cmath>
 4 #include <ctime>
 5 #include <queue>
 6 #include <stack>
 7 #include <cstdio>
 8 #include <string>
 9 #include <vector>
10 #include <cstdlib>
11 #include <cstring>
12 #include <iostream>
13 #include <algorithm>
14 using namespace std;
15 typedef unsigned long long ull;
16 typedef long long ll;
17 const int inf = 0x3f3f3f3f;
18 const double eps = 1e-8;
19 const int maxn = 1e5+10;
20 ll s[maxn],p[maxn],q[maxn];
21 ll res[maxn],minv[maxn];
22 int main(void)
23 {
24     #ifndef ONLINE_JUDGE
25         freopen("in.txt","r",stdin);
26     #endif
27     int t;
28     scanf ("%d",&t);
29     while (t--)
30     {
31         int n,m;
32         scanf ("%d%d",&n,&m);
33         minv[0] = inf;
34         for (int i = 0; i <  n; i++)
35         {
36             scanf ("%I64d%I64d",s+i,p+i);
37             res[i] = (s[i]-0) * p[i];
38         }
39         minv[n] = (ll)1<<50;
40         for (int i = n - 1; i >= 0; i--)
41         {
42             minv[i] = min(res[i],minv[i+1]);
43         }
44         for (int i = 0; i < m; i++)
45             scanf ("%I64d",q+i);
46         for (int i = 0; i < m; i++)
47         {
48             int idx = lower_bound(s,s+n,q[i]) - s;
49             ll ans = q[i] * p[idx-1];
50             printf("%I64d\n",min(ans,minv[idx]));
51         }
52     }
53     return 0;
54 }

1003:

题意:
几何题,有两个同心圆,撞到小圆会反弹,求在大圆中呆的时间

解法:

先判断能否进去,再判断能否碰撞

代码:

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <cmath>
 4 using namespace std;
 5
 6 const double eps=1e-14;
 7 int dcmp(double x)
 8 {
 9     if(fabs(x)<eps)
10         return 0;
11     else
12         return x<0?-1:1;
13 }
14
15
16 double dot(double x1,double y1,double x2,double y2)
17 {
18     return x1*x2+y1*y2;
19 }
20
21 int main()
22 {
23     //freopen("in.txt","r",stdin);
24     double rmax, rmin, r, x, y;
25     double vx, vy;
26     while(~scanf("%lf%lf%lf%lf%lf%lf%lf",&rmin, &rmax, &r, &x, &y, &vx, &vy))
27     {
28         if(dcmp(vx)==0)
29             vx=eps;
30         double k=vy/vx;
31         double d=fabs(y-k*x)/sqrt(k*k+1);
32
33
34         // 不能相交
35         if(d>=r+rmax || dot(x,y,vx,vy)>0)
36         {
37             printf("0\n");
38             continue;
39         }
40
41         if(d>r+rmin)
42         {
43             double l1=sqrt((rmax+r)*(rmax+r)-d*d);
44             double t=l1/sqrt(vx*vx+vy*vy)*2.;
45             printf("%.6f\n",t);
46             continue;
47         }
48         double l1=sqrt((rmax+r)*(rmax+r)-d*d);
49         double l2=sqrt((rmin+r)*(rmin+r)-d*d);
50         double t=(l1-l2)/sqrt(vx*vx+vy*vy)*2.;
51         printf("%.6f\n",t);
52     }
53
54     return 0;
55 }

1010:

题意:

有c(m,3)支队伍,起初可以选一支,每次打败某只队伍后可以换成被打败的队伍,打败是有概率的,最后求最大概率

解法:

数据范围不大,直接dp就可以了

代码:

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include<string.h>
 4 #include<algorithm>
 5 #include<string>
 6 #include<ctype.h>
 7 #include<math.h>
 8 using namespace std;
 9 #define eps 0.00000000001
10 int M,m,n;
11 double g[1010][1010];
12 int a[10010];
13 double dp[2][10010];
14 void ini()
15 {
16     M=m*(m-1)*(m-2)/6;
17     for(int i=0;i<M;i++)
18     {
19         for(int j=0;j<M;j++)
20             scanf("%lf",g[i]+j);
21     }
22     scanf("%d",&n);
23     for(int i=1;i<=n;i++)
24     {
25         scanf("%d",a+i);
26     }
27 }
28 void solve()
29 {
30     memset(dp,0,sizeof(dp));
31     for(int i=0;i<M;i++)
32     {
33         dp[0][i]=1.0;
34     }
35     for(int i=1;i<=n;i++)
36     {
37         for(int j=0;j<M;j++)
38         {
39             if(fabs(dp[(i-1)%2][j])<eps)
40             {
41                 continue;
42             }
43             dp[i%2][j]=max(dp[i%2][j],dp[(i-1)%2][j]*g[j][a[i]]);
44             dp[i%2][a[i]]=max(dp[i%2][a[i]],dp[(i-1)%2][j]*g[j][a[i]]);
45             dp[(i-1)%2][j]=0;
46         }
47     }
48     double ans=0;
49     for(int i=0;i<M;i++)
50     {
51         ans=max(ans,dp[n%2][i]);
52     }
53     printf("%.6f\n",ans);
54 }
55 int main()
56 {
57     while(scanf("%d",&m)!=EOF)
58     {
59         ini();
60         solve();
61     }
62     return 0;
63 }

1011:

题意:

给一个二维魔方的初始状态,求还原此魔方的最小步数,且步数不超过n步

解法:

由于限定了上界,所以直接dfs

代码:

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <memory.h>
 4 using namespace std;
 5
 6 int n;
 7 int state[24];
 8 const int same[][4]={
 9     {0,1,2,3},
10     {4,5,10,11},
11     {6,7,12,13},
12     {8,9,14,15},
13     {16,17,18,19},
14     {20,21,22,23}
15 };
16
17 const int change[][24]=
18 {
19     {1,3,0,2,23,22,4,5,6,7,10,11,12,13,14,15,16,17,18,19,20,21,9,8},
20     {2,0,3,1,6,7,8,9,23,22,10,11,12,13,14,15,16,17,18,19,20,21,5,4},
21     {20,1,22,3,10,4,0,7,8,9,11,5,2,13,14,15,6,17,12,19,16,21,18,23},
22     {6,1,12,3,5,11,16,7,8,9,4,10,18,13,14,15,20,17,22,19,0,21,2,23},
23     {0,1,11,5,4,16,12,6,2,9,10,17,13,7,3,15,14,8,18,19,20,21,22,23},
24     {0,1,8,14,4,3,7,13,17,9,10,2,6,12,16,15,5,11,18,19,20,21,22,23}
25 };
26 int tmp[24];
27 void Change(int type)
28 {
29     for(int i=0;i<24;i++)
30         tmp[i]=state[change[type][i]];
31
32     memcpy(state,tmp,sizeof tmp);
33 }
34
35
36 // 得到相同的面数
37 int getSame()
38 {
39     int ans=6;
40     for(int i=0;i<6;i++)
41         for(int j=0;j<4;j++)
42             if(state[same[i][0]]!=state[same[i][j]])
43             {
44                 ans--;
45                 break;
46             }
47     return ans;
48 }
49
50 int ans=0;
51 void dfs(int cur=0)
52 {
53     ans=max(ans,getSame());
54     if(cur>=n)
55         return ;
56     for(int i=0;i<6;i++)
57     {
58         Change(i);
59         dfs(cur+1);
60         Change(i^1);
61     }
62 }
63
64
65
66 int main()
67 {
68     //freopen("in.txt","r",stdin);
69
70     while(~scanf("%d",&n))
71     {
72         for(int i=0;i<24;i++)
73             scanf("%d",&state[i]);
74         ans=getSame();
75         dfs();
76         printf("%d\n",ans);
77     }
78
79
80     return 0;
81 }

时间: 2024-10-13 22:52:14

2013长沙regional部分题解(hdu4791-4801)的相关文章

2013 长沙邀请赛 ADEGH 题解

HDU 4565 So Easy! 类似fib的构造 设Fn = x + y*sqrt(b) 啪啦啪啦 #include <cstdio> #include <cstring> #include <vector> #include <cmath> #include <iostream> using namespace std; typedef vector<long long> vec; typedef vector<vec&g

HDU 4816 Bathysphere(数学)(2013 Asia Regional Changchun)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spherical deep-sea submersible which was unpowered and lowered into the ocean on a cable, and was used to conduct a series of dives under the sea. The Bathys

HDU 4791 Alice&#39;s Print Service (2013长沙现场赛,二分)

Alice's Print Service Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1855    Accepted Submission(s): 454 Problem Description Alice is providing print service, while the pricing doesn't seem to

HDU 4822 Tri-war(LCA树上倍增)(2013 Asia Regional Changchun)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4822 Problem Description Three countries, Red, Yellow, and Blue are in war. The map of battlefield is a tree, which means that there are N nodes and (N – 1) edges that connect all the nodes. Each country

2013 Asia Regional Changchun C

Little Tiger vs. Deep Monkey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 960    Accepted Submission(s): 344 Problem Description A crowd of little animals is visiting a mysterious laboratory

HDU 4791 Alice&#39;s Print Service(2013长沙区域赛现场赛A题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 解题报告:打印店提供打印纸张服务,需要收取费用,输入格式是s1 p1 s2 p2 s3 p3...表示打印区间s1到s2张纸的单价是p1,打印区间s2 到s3的单价是p2....最后是sn到无穷大的单价是pn,让你求打印k张纸的总费用最少是多少?有m次查询. 因为s1*p1 > s2 * p2 > s3*p3......,很显然,加入k所在的那个区间是第x个区间,那么最低费用要么是k * p

CUGBACM_Summer_Tranning3 2013长沙现场赛(二分+bfs模拟+DP+几何)

A题:二分 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 用lower_bound可以轻松解决,不过比赛的时候逗逼了. 刚开始没有预处理,所以队友给出一组数据的时候没通过,然后一时紧张又想不出什么好的解决办法,所以就没再继续敲代码.实在有点可惜了. #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #includ

2013 Asia Regional Changchun

Hard Code http://acm.hdu.edu.cn/showproblem.php?pid=4813 1 #include<cstdio> 2 char op[1024]; 3 int main(){ 4 int t,n,m; 5 while(~scanf("%d",&t)){ 6 while(t--){ 7 scanf("%d%d%s",&n,&m,op); 8 for(int i=0;i<n;i++){ 9

HDU 4793 Collision (2013长沙现场赛,简单计算几何)

Collision Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 685    Accepted Submission(s): 248Special Judge Problem Description There's a round medal fixed on an ideal smooth table, Fancy is tryin