2018杭电多校第五场

这场简直就是修罗场。。

B

爆搜,预处理降一下复杂度

#include <bits/stdc++.h>
using namespace std;
vector<int> perm[10][10];
int a[10];
int vis[10];
void init()
{
    for(int t = 1; t <= 9; t++)
    {
        for(int i = 1; i <= t; i++)
            a[i] = i;
        memset(vis, 0, sizeof(vis));
        do
        {
            int now = 0;
            for(int i = 1; i <= t; i++)
                now = now * 10 + a[i];
            int tmp = 0;
            for(int i = 1; i <= t; i++)
                if(vis[i] != now)
                {
                    vis[i] = now;
                    for(int j = a[i]; j != i; j = a[j])
                    {
                        vis[j] = now;
                        tmp++;
                    }
                }
            perm[t][tmp].push_back(now);
        }
        while(next_permutation(a + 1, a + t + 1));
    }
}
inline int apply(int mask)
{
    int ret = 0;
    int tmp = 1;
    while(mask)
    {
        ret += a[mask % 10] * tmp;
        mask /= 10;
        tmp *= 10;
    }
    return ret;
}

char n[12];
int t, k, mn, mx;
void solve()
{
    scanf("%s%d", n, &k);
    t = strlen(n);
    if(t == 10)
    {
        printf("1000000000 1000000000\n");
        return;
    }
    if(k >= t)
        k = t - 1;
    for(int i = 1; i <= t; i++)
        a[i] = n[i - 1] - '0';
    mn = 1000000000;
    mx = 0;
    int lj = 1;
    for(int i = 1; i < t; i++)
        lj *= 10;
    for(int i = 0; i <= k; i++)
        for(vector<int>::iterator it = perm[t][i].begin(); it != perm[t][i].end(); it++)
        {
            int now = apply(*it);
            if(now < lj)
                continue;
            now < mn ? mn = now : 0;
            now > mx ? mx = now : 0;
        }
    printf("%d %d\n", mn, mx);
}
int main()
{
    init();
    int T;
    scanf("%d", &T);
    for(int t1 = 1; t1 <= T; t1++)
        solve();
    return 0;
}

E

这个到其实是可以签的了的,只要在精度上苟活下来

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int _,m,R,x,y,r;

const double pi=acos(-1.);
double norm(double x) {
	return min(max(x,-1.0),1.0);
}
int main() {
	for (scanf("%d",&_);_;_--) {
		scanf("%d%d",&m,&R);
		double ans=2*pi*R;
		rep(i,0,m) {
			scanf("%d%d%d",&x,&y,&r);
			int d1=x*x+y*y;
			if (d1<(R-r)*(R-r)) continue;
			if (d1>(R+r)*(R+r)) continue;
//			printf("%.10f\n",ans);
			double t1=acos(norm((R*R+d1-r*r)/2./R/sqrt(d1)));
			ans-=2*t1*R;
			double t2=acos(norm((r*r+d1-R*R)/2./r/sqrt(d1)));
			ans+=2*t2*r;
		}
		printf("%.10f\n",ans);
	}
}

G

#include<algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include  <stdio.h>
#include   <math.h>
#include   <time.h>
#include   <vector>
#include   <bitset>
#include    <queue>
#include      <map>
#include      <set>
using namespace std;

unsigned X,Y,Z;

unsigned RNG61()
{
    X=X^(X<<11);
    X=X^(X>>4);
    X=X^(X<<5);
    X=X^(X>>14);
    unsigned W=X^(Y^Z);
    X=Y;
    Y=Z;
    Z=W;
    return Z;
}

const int N=100005;

int n,m,a[N],b[20][N],Log[N];

void Update(int l,int r,int z)
{
    int k=Log[r-l+1];
    b[k][l]=max(b[k][l],z);
    b[k][r-(1<<k)+1]=max(b[k][r-(1<<k)+1],z);
}

void solve()
{
    cin>>n>>m>>X>>Y>>Z;
    for(int j=0;j<20;j++)
        for(int i=1;i<=n;i++)
            b[j][i]=0;
    for(int i=1;i<=m;i++)
    {
        int x=RNG61()%n+1,y=RNG61()%n+1,z=RNG61()%(1<<30);
        Update(min(x,y),max(x,y),z);
    }
    for(int j=19;j;j--)
        for(int i=1;i+(1<<j)-1<=n;i++)
            b[j-1][i]=max(b[j-1][i],b[j][i]),b[j-1][i+(1<<j-1)]=max(b[j-1][i+(1<<j-1)],b[j][i]);
    long long Ans=0;
    for(int i=1;i<=n;i++)
        Ans=Ans^(i*(long long)b[0][i]);
    cout<<Ans<<endl;
}

int main()
{
    Log[2]=1;
    //递推求出log2(n) 
    for(int i=3;i<N;i++)
        Log[i]=Log[i>>1]+1;
    int t;cin>>t;
    while(t--)
        solve(); 
    return 0;
}

H

#include<algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include  <stdio.h>
#include   <math.h>
#include   <time.h>
#include   <vector>
#include   <bitset>
#include    <queue>
#include      <map>
#include      <set>
using namespace std;

const int N=100005;

int f[2][10][10][10],pos[2][10][10][10],n,m,l,r,T[N][10],G[N][10];
char s[N];

void Update(int a,int b,int c,int d,int e,int g)
{
    if(f[a][b][c][d]<e)
        f[a][b][c][d]=e,pos[a][b][c][d]=g;
}

void solve()
{
    scanf("%d %s",&n,s+1);
    m=0;l=r=1;
    for(int i=1;i<=n;i++)
        s[i]-='0';
    for(int i=0;i<=9;i++)
        T[n+1][i]=0;
    for(int i=n;i;i--)
        for(int j=9;j>=0;j--)
            T[i][j]=max(T[i+1][j]+(s[i]==j),j==9?0:T[i][j+1]);
    for(int i=1;i<=n;i++)
        for(int j=0;j<=9;j++)
            G[i][j]=max(G[i-1][j]+(s[i]==j),j==0?0:G[i][j-1]);//,cout<<i<<" "<<j<<" "<<G[i][j]<<endl;
    memset(f,-1,sizeof f);memset(pos,0,sizeof pos);
    for(int i=1;i<=n;i++)
    {
        int Now=i&1,Pre=Now^1;
        memset(f[Now],-1,sizeof(f[Now]));
        memset(pos[Now],0,sizeof(pos[Now]));
        for(int a=0;a<=9;a++)
            for(int b=0;b<=9;b++)
                for(int c=b;c>=a;c--)
                {
                    Update(Now,a,b,c,f[Pre][a][b][c]+(s[i]==c),pos[Pre][a][b][c]);
                    if(c!=b)
                        Update(Now,a,b,c,f[Now][a][b][c+1],pos[Now][a][b][c+1]);
                    Update(Now,a,b,c,G[i-1][a]+(s[i]==c),i);
                }
        for(int a=0;a<=9;a++)
            for(int b=0;b<=9;b++)
                for(int c=b;c>=a;c--)
                {
                    int k=f[Now][a][b][c]+T[i+1][b];
                    if(k>m)
                        m=k,l=pos[Now][a][b][c],r=i; 
                }
    }
    if(l==0)
        l=r=1;
    cout<<m<<" "<<l<<" "<<r<<endl;
}

int main()
{
    int t;cin>>t;
    while(t--)
        solve();
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_38759433/article/details/81782577
今日推荐