Codeforces Beta Round #67 (Div. 2)

Codeforces Beta Round #67 (Div. 2)

http://codeforces.com/contest/75

A

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 1000006
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef unsigned long long ull;
14 
15 
16 int main(){
17     #ifndef ONLINE_JUDGE
18      //   freopen("input.txt","r",stdin);
19     #endif
20     std::ios::sync_with_stdio(false);
21     int a,b,c;
22     cin>>a>>b;
23     c=a+b;
24     int ccc=0;
25     int aa=0,bb=0,cc;
26     int p=1;
27     while(a){
28         int tmp=a%10;
29         if(tmp!=0){
30            aa+=(tmp)*p;
31            p*=10;
32         }
33         a/=10;
34     }
35     p=1;
36     while(b){
37         int tmp=b%10;
38         if(tmp!=0){
39            bb+=(tmp)*p;
40            p*=10;
41         }
42         b/=10;
43     }
44     p=1;
45     while(c){
46         int tmp=c%10;
47         if(tmp!=0){
48            ccc+=(tmp)*p;
49            p*=10;
50         }
51         c/=10;
52     }
53     cc=aa+bb;
54     if(cc==ccc) cout<<"YES"<<endl;
55     else cout<<"NO"<<endl;
56 }
View Code

 

B

模拟

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 1000006
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef unsigned long long ull;
14 
15 
16 int main(){
17     #ifndef ONLINE_JUDGE
18      //   freopen("input.txt","r",stdin);
19     #endif
20     std::ios::sync_with_stdio(false);
21     string me;
22     cin>>me;
23       int n;
24     cin>>n;
25       map<string,int>M,S{{"posted",15},{"commented",10},{"likes",5}};
26       for(string a,b,c,x;cin>>a>>b>>c>>x;M[a],M[c])
27     {
28         if(c=="on")c=x,cin>>x;
29         c.pop_back();c.pop_back();
30         if(a==me)M[c]+=S[b];
31         if(c==me)M[a]+=S[b];
32       }
33       vector<pair<int,string>>V;
34       for(map<string,int>::iterator it=M.begin();it!=M.end();it++)V.emplace_back(-it->second,it->first);
35       sort(V.begin(),V.end());
36       for(int i=0;i<V.size();i++)if(V[i].second!=me)cout<<V[i].second<<endl;
37 }
View Code

 

C

二分+gcd 

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 1000006
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef unsigned long long ull;
14 
15 int aa,bb,l,r,x,y;
16 int a[100005];
17 
18 int main(){
19     #ifndef ONLINE_JUDGE
20      //   freopen("input.txt","r",stdin);
21     #endif
22     std::ios::sync_with_stdio(false);
23     cin>>aa>>bb;
24     int n;
25     cin>>n;
26     int gcd=__gcd(aa,bb);
27     int co=1;
28     int gg=sqrt(gcd);
29     a[co++]=1;
30     for(int i=2;i<=gg;i++){
31         if(gcd%i==0){
32             a[co++]=i;
33             if(gcd/i!=gg){
34                 a[co++]=gcd/i;
35             }
36         }
37     }
38     a[co++]=gcd;
39     sort(a+1,a+co);
40     int mid;
41     for(int i=1;i<=n;i++){
42         cin>>x>>y;
43         l=1,r=co-1;
44         while(l<=r){
45             mid=l+r>>1;
46             if(a[mid]<=y) l=mid+1;
47             else {
48                 r=mid-1;
49             }
50         }
51         if(a[r]>y) r--;
52         if(a[r]>=x&&a[r]<=y) cout<<a[r]<<endl;
53         else cout<<-1<<endl;
54     }
55 }
View Code

 

D

应该是最大子段和的加强版吧,把最大前缀和,最大后缀和,最大子区间和求出来,然后找最大值

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 1000006
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef unsigned long long ull;
14 
15 ll maxl[55],maxr[55],sum[55],dp[55],Right;
16 
17 int main(){
18     #ifndef ONLINE_JUDGE
19      //   freopen("input.txt","r",stdin);
20     #endif
21     std::ios::sync_with_stdio(false);
22     int n,m;
23     cin>>n>>m;
24     int num;
25     int x;
26     for(int i=1;i<=n;i++){
27         cin>>num;
28         maxl[i]=dp[i]=-0x3f3f3f3f;
29         Right=0;
30         for(int j=1;j<=num;j++){
31             cin>>x;
32             sum[i]+=x;
33             maxl[i]=max(sum[i],maxl[i]);
34             Right+=x;
35             dp[i]=max(dp[i],Right);
36             if(Right<0) Right=0;
37         }
38         maxr[i]=Right;
39     }
40     ll ans=-0x3f3f3f3f;
41     Right=0;
42     for(int i=1;i<=m;i++){
43         cin>>x;
44         ans=max(max(ans,dp[x]),Right+maxl[x]);  
45         Right=max(Right+sum[x],maxr[x]);
46     }
47     cout<<ans<<endl;
48 }
View Code

 

E

几何,分类讨论即可

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 1000006
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef unsigned long long ull;
14 
15 struct Point{
16     double x,y;
17 }a[105],h[105],s,e;
18 double ans;
19 int p[105],n,m;
20 
21 double dis(Point a, Point b) {
22     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
23 }
24 
25 double cross(Point s, Point a, Point b) {
26     return (a.x - s.x) * (b.y - s.y) - (b.x - s.x) * (a.y - s.y);
27 }
28 
29 void check(Point a, Point b, Point c, Point d, int i) {
30     double t1 = cross(a, c, b), t2 = cross(a, b, d), t3 = cross(c, a, d), t4 = cross(c, d, b);
31     if (fabs(t1) < eps && fabs(t2) < eps) return ;
32     if (fabs(dis(a, c) + dis(c, b) - dis(a, b)) < eps) {
33         h[m] = c; p[m] = i; ++m; return ;
34     }
35     if (t1 * t2 > eps && t3 * t4 > eps) {
36         h[m].x = (t1 * d.x + t2 * c.x) / (t1 + t2);
37         h[m].y = (t1 * d.y + t2 * c.y) / (t1 + t2);
38         p[m] = i; ++m;
39     }
40 }
41 
42 double getl(int st, int en, int x, int y) {
43     double res; st = (st + 1) % n; res = 0;
44     for (int i = st; i != en; i = (i + 1) % n)
45         res += dis(a[i], a[(i + 1) % n]);
46     return res + dis(h[x], a[st]) + dis(a[en], h[y]);
47 }
48 
49 
50 int main(){
51     #ifndef ONLINE_JUDGE
52      //   freopen("input.txt","r",stdin);
53     #endif
54    // std::ios::sync_with_stdio(false);
55     cin>>s.x>>s.y>>e.x>>e.y>>n;
56     for (int i = 0; i < n; ++i) cin>>a[i].x>>a[i].y;
57     for (int i = 0; i < n; ++i) check(s, e, a[i], a[(i + 1) % n], i);
58     if (m == 2) {
59         if (dis(s, h[0]) > dis(s, h[1])) swap(h[0], h[1]), swap(p[0], p[1]);
60         ans = min(getl(p[0], p[1], 0, 1), getl(p[1], p[0], 1, 0));
61         ans = min(ans, dis(h[0], h[1]) * 2);
62         ans += dis(s, h[0]) + dis(h[1], e);
63     }
64     else ans = dis(s, e);
65     printf("%.7f\n",ans);
66 }
View Code

 

posted on 2019-03-04 11:42  Fighting_sh  阅读(160)  评论(0编辑  收藏  举报

导航