hdu 2018 多校 第五场

Posted mygirlfriends

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu 2018 多校 第五场相关的知识,希望对你有一定的参考价值。

1002 小洛洛

开场挂了N发插入排序的我( 最后还是要靠小洛洛写暴力

技术分享图片
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <cmath>
 5 #include <cstdlib>
 6 #include <algorithm>
 7 using namespace std;
 8 
 9 const int N = 12;
10 
11 int min_(char s[], int mul, int k, bool fst = false) {
12   if(!*s)
13     return 0;
14   char x = *s;
15   if(k)
16     for(char *p = s; *p; ++p)
17       if(!fst || *p != 0)
18         x = min(x, *p);
19   int mn = 1000000000;
20   if(*s == x)
21     mn = min_(s + 1, mul / 10, k);
22   else
23     for(char *p = s + 1; *p; ++p)
24       if(*p == x) {
25         swap(*s, *p);
26         mn = min(mn, min_(s + 1, mul / 10, k - 1));
27         swap(*s, *p);
28       }
29   return (x - 0) * mul + mn;
30 }
31 int max_(char s[], int mul, int k) {
32   if(!*s)
33     return 0;
34   char x = *s;
35   if(k)
36     for(char *p = s; *p; ++p)
37       x = max(x, *p);
38   int mx = 0;
39   if(*s == x)
40     mx = max_(s + 1, mul / 10, k);
41   else
42     for(char *p = s + 1; *p; ++p)
43       if(*p == x) {
44         swap(*s, *p);
45         mx = max(mx, max_(s + 1, mul / 10, k - 1));
46         swap(*s, *p);
47       }
48   return (x - 0) * mul + mx;
49 }
50 
51 int main() {
52   int t;
53   scanf("%d", &t);
54   while(t--) {
55     int k;
56     char s[N];
57     scanf("%s%d", s, &k);
58     int mul = 1;
59     for(char *p = s + 1; *p; ++p)
60       mul *= 10;
61     int mn = min_(s, mul, k, true);
62     int mx = max_(s, mul, k);
63     printf("%d %d
", mn, mx);
64   }
65   return 0;
66 }
View Code

 

1005 BPM136

用圆的面积交模板改一下就好了

技术分享图片
 1 /* ***********************************************
 2 Author        :BPM136
 3 Created Time  :2018/8/6 12:38:56
 4 File Name     :1005.cpp
 5 ************************************************ */
 6 
 7 #include<iostream>
 8 #include<cstdio>
 9 #include<algorithm>
10 #include<cstdlib>
11 #include<cmath>
12 #include<cstring>
13 #include<vector>
14 using namespace std;
15 
16 const int N = 105;
17 const double pi = acos(-1.0);
18 
19 struct point {
20     double x,y;
21 };
22 
23 struct circle {
24     int x,y;
25     int R;
26 }c[N];
27 int m,R;
28 
29 double cirinter(int r1,int x2,int y2,int r2) {
30     double d,s,t,a1,a2,s1,s2,s3;
31     d=sqrt((-x2)*(-x2)+(-y2)*(-y2));
32     if(d>=r1+r2)return 0;
33     else if(d<r1-r2) return 0; 
34     else
35     {
36         a1=acos((r1*r1+d*d-r2*r2)/(2*r1*d));
37         a2=acos((r2*r2+d*d-r1*r1)/(2*r2*d));
38         s1=2*a1*r1;
39         s2=2*a2*r2;
40         s=s2-s1;
41     }
42     return s;
43 }
44 
45 int main() {
46     int T;
47     scanf("%d",&T);
48     while(T--) {
49         scanf("%d%d",&m,&R);
50         for(int i=1;i<=m;i++) scanf("%d%d%d",&c[i].x,&c[i].y,&c[i].R);
51         double ans=2*pi*R;
52         for(int i=1;i<=m;i++) ans+=cirinter(R,c[i].x,c[i].y,c[i].R);
53         printf("%.10f
",ans);
54     }
55     return 0;
56 }
View Code

 

1007 BPM136

正解st表下压待补

线段树据说势能分析一下是对的?

线段树版本

技术分享图片
 1 /* ***********************************************
 2 Author        :BPM136
 3 Created Time  :2018/8/6 17:45:43
 4 File Name     :1007G.cpp
 5 ************************************************ */
 6 
 7 #include<iostream>
 8 #include<cstdio>
 9 #include<algorithm>
10 #include<cstdlib>
11 #include<cmath>
12 #include<cstring>
13 #include<vector>
14 using namespace std;
15 
16 typedef unsigned int UI;
17 typedef long long ll;
18 
19 UI X,Y,Z;
20 
21 UI RNG61() {
22     X=X^(X<<11);
23     X=X^(X>>4);
24     X=X^(X<<5);
25     X=X^(X>>14);
26     UI W=X^(Y^Z);
27     X=Y;
28     Y=Z;
29     Z=W;
30     return Z;
31 }
32 
33 const int N = 100005;
34 const unsigned int MOD = (1U<<30);
35 
36 int n,m;
37 
38 #define LSON (k<<1)
39 #define RSON (k<<1|1)
40 #define MID ((l+r)>>1)
41 
42 int mx[N<<2];
43 
44 void update(int k,int l,int r,int ll,int rr,int val) {
45     if(mx[k]>=val) return ;
46     if(l==ll && r==rr) {
47         mx[k]=val;
48         return ;
49     }
50     int mid=MID;
51     if(rr<=mid) update(LSON,l,mid,ll,rr,val); 
52     else if(ll>mid) update(RSON,mid+1,r,ll,rr,val);
53     else {
54         update(LSON,l,mid,ll,mid,val);
55         update(RSON,mid+1,r,mid+1,rr,val);
56     }
57 }
58 
59 int query(int k,int pos) {
60     int l=1,r=n;
61     int ret=0;
62     while(l!=r) {
63         ret=max(ret,mx[k]);
64         int mid=MID;
65         if(pos<=mid) {
66             r=mid;
67             k=LSON;
68         } else {
69             l=mid+1;
70             k=RSON;
71         }
72     }
73     ret=max(ret,mx[k]);
74     return ret;
75 }
76 
77 int main() {
78     int T;
79     cin>>T;
80     while(T--) {
81         cin>>n>>m>>X>>Y>>Z;
82         memset(mx,0,sizeof(mx));
83         for(int i=1;i<=m;i++) {
84             UI x=RNG61();
85             UI y=RNG61();
86             UI w=RNG61();
87             UI l,r,v;
88             l=min(x%n+1, y%n+1);
89             r=max(x%n+1, y%n+1);
90             while(w>MOD) w-=MOD;
91             update(1,1,n,l,r,w);
92         }
93         ll ans=0;
94         //for(int i=1;i<=n;i++) cerr<<query(1,i)<<‘ ‘; cerr<<endl;
95         for(int i=1;i<=n;i++) ans=ans^((ll)query(1,i)*i);
96         cout<<ans<<endl;
97     }
98     return 0;
99 }
View Code

 

 

1008 小洛洛

dp 枚举翻转的值域dp就好了

技术分享图片
  1 #include <cstdio>
  2 #include <cstring>
  3 #include <iostream>
  4 #include <cmath>
  5 #include <cstdlib>
  6 #include <algorithm>
  7 using namespace std;
  8 
  9 template<int BI, int BO>
 10 struct IO_ {
 11     char bufi[BI + 1], *qi, bufo[BO], *qo;
 12     IO_(): qi(bufi + BI), qo(bufo) {}
 13     ~IO_() { o_(EOF); }
 14     int i_() {
 15         if(qi == bufi + BI) bufi[fread(bufi, 1, BI, stdin)] = , qi = bufi;
 16         return *qi ? *qi++ : EOF;
 17     }
 18     void o_(int c) {
 19         if(c != EOF) *qo++ = c;
 20         if(qo == bufo + BO || (c == EOF && qo != bufo))
 21             fwrite(bufo, qo - bufo, 1, stdout), qo = bufo;
 22     }
 23     IO_ &operator>>(int &ret) {
 24         ret = 0; int c;
 25         while(isspace(c = i_()));
 26         bool bm = c == - ? (c = i_(), true) : false;
 27         while(ret = ret * 10 - (c - 0), isdigit(c = i_()));
 28         if(!bm) ret = -ret;
 29         return *this;
 30     }
 31     IO_ &operator>>(char *p) {
 32         int c; while(isspace(c = i_()));
 33         do *p++ = c; while(!isspace(c = i_()));
 34         *p = ;
 35         return *this;
 36     }
 37     IO_ &operator<<(char c) { return o_(c), *this; }
 38     IO_ &operator<<(char *p) { while(*p) o_(*p++); return *this; }
 39     IO_ &operator<<(int x) {
 40         char s[12] = {}, *p = s + 11;
 41         bool bm = x < 0 ? true : (x = -x, false);
 42         while(*--p = 0 - x % 10, x /= 10);
 43         if(bm) *--p = -;
 44         while(*p) o_(*p++);
 45         return *this;
 46     }
 47 };
 48 
 49 const int N = 100002;
 50 char s[N];
 51 int l[N][10], r[N][10];
 52 int f[N][10][2];
 53 
 54 void init_(int n) {
 55   for(int i = 0; i < n; ++i)
 56     for(int j = 0; j <= 9; ++j)
 57       l[i][j] = max(j ? l[i][j - 1] : 0, (i ? l[i - 1][j] : 0) + (j == s[i]));
 58   for(int i = n - 1; i >= 0; --i)
 59     for(int j = 9; j >= 0; --j)
 60       r[i][j] = max(j + 1 <= 9 ? r[i][j + 1] : 0, (i + 1 < n ? r[i + 1][j] : 0) + (j == s[i]));
 61 }
 62 
 63 int main() {
 64   auto &io = *new IO_<0x10000, 0x10000>;
 65 
 66   int t;
 67   io >> t;
 68   while(t--) {
 69     int n;
 70     io >> n >> s;
 71     for(int i = 0; i < n; ++i)
 72       s[i] -= 0;
 73 
 74     init_(n);
 75 
 76     int ans = 1, ansl = 0, ansr = 0;
 77     for(int a = 0; a <= 9; ++a)
 78       for(int b = a; b <= 9; ++b)
 79         for(int i = 0; i < n; ++i) {
 80           int cl = i ? l[i - 1][a] : 0;
 81           int cr = i + 1 < n ? r[i + 1][b] : 0;
 82           for(int j = b; j >= a; --j) {
 83             f[i][j][0] = ~0x7FFFFFFF, f[i][j][1] = -1; // must not be ans
 84             if(j < b)
 85               f[i][j][0] = f[i][j + 1][0], f[i][j][1] = f[i][j + 1][1];
 86             if(i > 0 && f[i - 1][j][0] + (j == s[i]) > f[i][j][0])
 87               f[i][j][0] = f[i - 1][j][0] + (j == s[i]), f[i][j][1] = f[i - 1][j][1];
 88             if(j == s[i] && cl + 1 > f[i][j][0])
 89               f[i][j][0] = cl + 1, f[i][j][1] = i;
 90             int cur = f[i][j][0] + cr;
 91             if(cur > ans) {
 92               ans = cur;
 93               ansl = f[i][j][1];
 94               ansr = i;
 95             }
 96           }
 97         }
 98     io << ans <<   << ansl + 1 <<   << ansr + 1 << 
;
 99   }
100 
101   delete &io;
102   return 0;
103 }
View Code

 

以上是关于hdu 2018 多校 第五场的主要内容,如果未能解决你的问题,请参考以下文章

[2019杭电多校第五场][hdu6629]string matching

[补]2019HDU杭电多校第五场H

[2019杭电多校第五场][hdu6624]fraction

暑假N天乐比赛篇 —— 2019杭电暑期多校训练营(第五场)

[2019杭电多校第五场][hdu6628]permutation 1

hdu多校第五场1007 (hdu6630) permutation 2 dp