# 2019HDU多校第十场

（撒花！二十场打完了。虽然题解（riji）咕咕咕了好几场。

1003 Valentine's Day

1 #include<bits/stdc++.h>
2 using namespace std;
3 const int maxn=1e4+100;
4 double p[maxn];
5 bool cmp(double A,double B) {return A>B;}
6 void rua()
7 {
8     int n;scanf("%d",&n);
9     double ans=0.0,res=0.0,tmp=1.0;
10     for (int i=1;i<=n;i++) scanf("%lf",&p[i]);
11     sort(p+1,p+1+n,cmp);
12     if(p[1]==1.0) {printf("%.12lf\n",p[1]);return;}
13     for (int i=1;i<=n;i++)
14     {
15         double kk=1.0-p[i];
16         tmp*=kk;
17         double tt=p[i]/kk;
18         res+=tt;
19         ans=max(ans,tmp*res);
20     }
21     printf("%.12lf\n",ans);
22     return;
23 }
24 int main()
25 {
26     int t;scanf("%d",&t);
27     while(t--) rua();
28     return 0;
29 }
1003

1005 Welcome Party

1 #include<bits/stdc++.h>
2 using namespace std;
3 typedef long long ll;
4 const int maxn=1e5+10;
5 const ll INF=1e18+10;
6 struct node{ll x,y;}a[maxn];
7 bool cmp(node p,node q){return p.x<q.x;}
8 set<ll>s;   ll mx[maxn];
9 int main(){
10     int t,n;scanf("%d",&t);
11     while (t--){
12         scanf("%d",&n);
13         for (int i=1;i<=n;i++)scanf("%lld%lld",&a[i].x,&a[i].y);
14         sort(a+1,a+1+n,cmp);
15         ll mxx=0; mx[n+1]=0;
16         for (int i=n;i>=1;i--){
17             if (a[i].y>mxx) mxx=a[i].y;
18             mx[i]=mxx;
19         }
20         s.clear();ll ans=INF;
21         for (int i=1;i<=n;i++){
22             ll aa=a[i].x,bb=mx[i+1];
23             if(i!=n) ans=min(ans,abs(bb-aa));
24             if(!ans) break;
25             if (bb>aa||s.empty()) {s.insert(a[i].y);continue;}
26             auto it=s.lower_bound(aa);
27             if(it!=s.end()) ans=min(ans,abs((*it)-aa));
28             if(it!=s.begin()){
29                 --it;
30                 ans=min(ans,abs((*it)-aa));
31             }
32             if(!ans) break;
33             s.insert(a[i].y);
34         }
35         printf("%lld\n",ans);
36     }
37     return 0;
38 }
1005

1009 Block Breaker

1 #include<bits/stdc++.h>
2 using namespace std;
3 const int maxn=2007;
4 int vis[maxn][maxn];
5 int n,m,q;
6 int dx[]={0,0,1,-1};
7 int dy[]={1,-1,0,0};
8 struct node{int x,y;};
9 bool check(int x,int y)
10 {
11     int numx=0,numy=0;
12     for (int i=0;i<4;i++)
13     {
14         int xx=x+dx[i],yy=y+dy[i];
15         if (xx<1 || xx>n || yy<1 || yy>m) continue;
16         if (vis[xx][yy]){
17             if (i==0 || i==1) numx++;
18             else numy++;
19         }
20     }
21     return (numx>=1 && numy>=1);
22 }
23
24 int bfs(int x,int y)
25 {
26     queue<node> Q;
27     node cur,nex;
28     cur.x=x;cur.y=y;
29     Q.push(cur);vis[x][y]=1;
30     int res=0;
31     while (!Q.empty())
32     {
33         cur=Q.front();Q.pop(); res++;
34         for (int i=0;i<4;i++)
35         {
36             int xx=cur.x+dx[i],yy=cur.y+dy[i];
37             if (xx<1 || xx>n || yy<1 || yy>m) continue;
38             if(check(xx,yy) && !vis[xx][yy])
39             {
40                 nex.x=xx;nex.y=yy;
41                 Q.push(nex);
42                 vis[xx][yy]=1;
43             }
44         }
45     }
46     return res;
47 }
48 void rua()
49 {
50     scanf("%d%d%d",&n,&m,&q);
51     for (int i=0;i<=n;i++) for (int j=0;j<=m;j++) vis[i][j]=0;
52     while (q--)
53     {
54         int x,y;scanf("%d%d",&x,&y);
55         int ans;
56         if(vis[x][y]) ans=0;
57         else ans=bfs(x,y);
58         printf("%d\n",ans);
59     }
60     return;
61 }
62 int main()
63 {
64     int t;scanf("%d",&t);
65     while(t--) rua();
66     return 0;
67 }
1009

1011 Make Rounddog Happy

posted @ 2019-08-22 02:48  Changer-qyz  阅读(353)  评论(0编辑  收藏  举报