zoukankan      html  css  js  c++  java
  • 2018icpc南京

    A题 莽结论,注意特判0

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pll;
    const int N=1e5+10;
    int main(){
        ll n,k;
        cin>>n>>k;
        if(n==0){
            cout<<"Austin"<<endl;
            return 0;
        }
        if(k==1){
            if(n%2==1)cout<<"Adrien"<<endl;
            else cout<<"Austin"<<endl;
        }else cout<<"Adrien"<<endl;
        return 0;
    }
    View Code

    D题 最小球覆盖,使用模板或者模拟退火算法

    #include<bits/stdc++.h>
    using namespace std;
    #pragma warning(disable:4996)
    const double eps = 1e-8;
    struct point3D
    {
        double x, y, z;
    } p[105];
    int n;
    double dis(point3D a, point3D b)
    {
        return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y) + (a.z - b.z)*(a.z - b.z));
    }
    double solve()
    {
        double step = 10000, ans = 1e30, mt;
        point3D z;
        z.x = z.y = z.z = 0;
        int s = 0;
        while (step > eps)
        {
            for (int i = 0; i < n; i++)
                if (dis(z, p[s]) < dis(z, p[i]))
                    s = i;
            mt = dis(z, p[s]);
            ans = min(ans, mt);
            z.x += (p[s].x - z.x) / mt * step;
            z.y += (p[s].y - z.y) / mt * step;
            z.z += (p[s].z - z.z) / mt * step;
            step *= 0.98;
        }
        return ans;
    }
    int main()
    {
        double ans;
        while (scanf("%d", &n) != EOF)
        {
            for (int i = 0; i < n; i++)
                scanf("%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z);
            ans = solve();
            printf("%.7f
    ", ans);
        }
        return 0;
    }
    View Code

    I 最大流

    #include<bits/stdc++.h>
    using namespace std;
    const int inf=0x3f3f3f3f;
    const int N=1e4+10,M=2e5+10;
    int h[N],ne[M],e[M],w[M],idx;
    int n,m,S,T,E;
    int d[N],f[M],cur[N];
    int k;
    void add(int a,int b,int c){
        e[idx]=b,ne[idx]=h[a],f[idx]=c,h[a]=idx++;
        e[idx]=a,ne[idx]=h[b],f[idx]=0,h[b]=idx++;
    }
    int bfs(){
        memset(d,-1,sizeof d);
        d[S]=0;
        cur[S]=h[S];
        queue<int> q;
        q.push(S);
        while(q.size()){
            int t=q.front();
            q.pop();
            for(int i=h[t];i!=-1;i=ne[i]){
                int j=e[i];
                if(d[j]==-1&&f[i]){
                    cur[j]=h[j];
                    d[j]=d[t]+1;
                    if(j==T)
                    return true;
                    q.push(j);
                }
            }
        }
        return false;
    }
    int find(int u,int limit){
        if(u==T){
            return limit;
        }
        int i;
        int flow=0;
        for(i=cur[u];i!=-1&&flow<limit;i=ne[i]){
            cur[u]=i;
            int j=e[i];
            if(d[j]==d[u]+1&&f[i]){
                int t=find(j,min(f[i],limit-flow));
                if(!t)
                d[j]=-1;
                else{
                    f[i]-=t;
                    f[i^1]+=t;
                    flow+=t;
                }
     
            }
        }
        return flow;
    }
    int dinic(){
        int flow;
        int r=0;
        while(bfs()){
            while(flow=find(S,inf))
                r+=flow;
        }
        return r;
    }
    int main(){
        memset(h,-1,sizeof h);
        int i;
        cin>>n>>m>>k;
        S=0,T=n+m+1,E=n+m+2;
        for(int i=1;i<=n;i++){
            add(0,i,1);
            add(E,i,1);
        }
        add(0,E,k);
        for(int i=1;i<=n;i++){
            int t;
            cin>>t;
            for(int j=1;j<=t;j++){
                int x;
                cin>>x;
                add(i,n+x,1);
            }
        }
        for(int i=1;i<=m;i++){
            add(n+i,T,1);
        }
        cout<<dinic()<<endl;
    }
    View Code

    J 对于每一位算区间贡献

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pll;
    const int N=1e6+10;
    ll a[N][2];//a[n][0]->pre  a[n][1]->new
    ll vis[N];
    ll p[N];
    int cnt;
    void init(){
        int i;
        vis[1]=1;
        a[1][0]=-1;
        for(i=2;i<=1e6;i++){
            if(!vis[i]){
                a[i][0]=-1;
                a[i][1]=i;
                p[++cnt]=i;
            }
            for(int j=1;j<=cnt&&p[j]*i<=1000000;j++){
                vis[p[j]*i]=1;
                a[p[j]*i][0]=i;
                a[p[j]*i][1]=0;
                if(i%p[j]==0)break;
                a[p[j]*i][0]=i;
                a[p[j]*i][1]=p[j];
            }
        }
    }
    ll g[N];
    int main(){
        init();
        int n;scanf("%d",&n);
        ll sum=0;
        for(ll i=1;i<=n;i++){
            int x;    scanf("%d",&x);
            do{
                int t=a[x][1];
                if(t!=0)
                sum+=(i-g[t])*(n-i+1);
                g[t]=i;
                x=a[x][0];
                if(x==-1)break;
            }while(1);
        }
        cout<<sum<<endl;
        return 0;
    }
    View Code

    K 随机化算法

    #include<bits/stdc++.h>
    using namespace std;
    int main(void)
    {
        int n;
        srand(time(0));
        n = 50000;
        string s;
        char a[5]= "UDRL";
        while(n--) s += a[rand()%4];
        cout<<s<<endl;
       return 0;
    }
    View Code
    没有人不辛苦,只有人不喊疼
  • 相关阅读:
    监听浏览器使用不同版本js并且处理ie兼容getElementByClassName
    超出字数部分省略(主要解决不兼容;display: -webkit-box;的浏览器)
    highcharts图表
    整理前端css/js/jq常见问题及解决方法(1)
    [转载]移动页面所需meta元素和Viewport窗口知识点
    在ie和chrome浏览器中滚动条样式的设置
    关于:before :after
    mysql备份与还原
    使用xkbeancomparator对比javabean,生成操作记录
    SSO单点登录和CAS
  • 原文地址:https://www.cnblogs.com/ctyakwf/p/13843428.html
Copyright © 2011-2022 走看看