码迷,mamicode.com
首页 > 其他好文 > 详细

ACM-ICPC-Swiss-Subregional 2017 训练日志

时间:2018-06-16 13:36:08      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:ext   puts   queue   run   tchar   effective   .com   get   chess   

solved 7 (2/59)

Chess 

 

 

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

template<class T>
inline void read(T &ret){
    int sign=1;
    char c=getchar();
    while(c!=- && (c>9||c<0))c=getchar();
    if(c==-)sign=-1;
    else ret=c-0;
    while(c=getchar(),c>=0&&c<=9){
        ret=ret*10+c-0;
    }
    ret*=sign;
}


ll a[200005];
vector<ll> vec[200005];
multiset<ll> st;
unordered_set<ll> st2;
multiset<ll>::iterator it;
int cnt;
int n;
ll maxv=0;
bool zero=0;

int main(){
    read(n);
    for(int i=1;i<=n;i++){
        read(a[i]);
        st.insert(a[i]);
        st2.insert(a[i]);
        if(!a[i])zero=1;
        maxv = max(maxv,a[i]);
    }
    if(zero){
        for(int j=0;;j++){
            if(st.count((1LL<<j))==0){
                return cout<<(1LL<<j),0;
            }
        }
    }

    vec[++cnt].push_back(1);
    st.erase(st.find(1));

    while(1){
        if(st.size()==0)break;

        ll val = vec[cnt].back();
        it = st.find(val*2);
        if(it==st.end()){
            vec[++cnt].push_back(*st.begin());
            st.erase(st.begin());
        } else {
            vec[cnt].push_back(val*2);
            st.erase(it);
        }
    }

    ll valend = vec[1].back()*2;
    ll ans = 0x3f3f3f3f3f3f3f3f;

    multiset<pair<ll,int> >stt;

    for(int i=2;i<=cnt;i++){
        ll mod = valend - vec[i].front();
        if(mod<=maxv)continue;
        stt.insert(make_pair(mod,i));
    }

    if(cnt==1){
        ans = maxv+1;
    }
    else if(cnt==2){
        ans = valend - vec[2][0];
    }

    for(auto pp:stt){
        ll mod = pp.first;
        int id = pp.second;
        if(st2.count(vec[id].back()*2%mod)){
            if(cnt==3||st2.count(((vec[id].back()*2%mod)*2)%mod)) ans = min(ans , mod);
        }
    }
    cout<<ans;
    return 0;
}

 

 

 

B - Triangle in a Triangle 

#include <bits/stdc++.h>
using namespace std;
#define maxn 1000006
double ax,ay;
double bx,by;
double cx,cy;

int dista[maxn],distb[maxn],distc[maxn];
int ab,bc,ca;

double a1x,a1y,a2x,a2y;
double b1x,b1y,b2x,b2y;
double c1x,c1y,c2x,c2y;

double lenab,lenbc,lenca;

double dis(double x1,double y1,double x2,double y2){
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

double mj(double x1,double y1,double x2,double y2,double x3,double y3){
    double a = dis(x1,y1,x2,y2);
    double b = dis(x2,y2,x3,y3);
    double c = dis(x3,y3,x1,y1);
    double p = (a+b+c)/2;
    return sqrt(p*(p-a)*(p-b)*(p-c));
}

int main(){
    while(cin>>ax>>ay>>bx>>by>>cx>>cy){

        lenab = dis(ax,ay,bx,by);
        lenbc = dis(bx,by,cx,cy);
        lenca = dis(cx,cy,ax,ay);

        cin>>ab;
        for(int i=1;i<=ab;i++){
            scanf("%d",dista+i);
        }
        cin>>bc;
        for(int i=1;i<=bc;i++){
            scanf("%d",distb+i);
        }
        cin>>ca;
        for(int i=1;i<=ca;i++){
            scanf("%d",distc+i);
        }
        sort(dista+1,dista+1+ab);
        sort(distb+1,distb+1+bc);
        sort(distc+1,distc+1+ca);

        a1x = (ax - bx)*(lenab - dista[1])/(lenab) + bx;
        a1y = (ay - by)*(lenab - dista[1])/(lenab) + by;

        b1x = (ax - bx)*(lenab - dista[ab])/lenab + bx;
        b1y = (ay - by)*(lenab - dista[ab])/lenab + by;

        b2x = (cx - bx)*(distb[1])/lenbc + bx;
        b2y = (cy - by)*(distb[1])/lenbc + by;

        c1x = (cx - bx)*(distb[bc])/lenbc + bx;
        c1y = (cy - by)*(distb[bc])/lenbc + by;

        c2x = (cx - ax)*(lenca - distc[1])/lenca + ax;
        c2y = (cy - ay)*(lenca - distc[1])/lenca + ay;

        a2x = (cx - ax)*(lenca - distc[ca])/lenca + ax;
        a2y = (cy - ay)*(lenca - distc[ca])/lenca + ay;

        double ans = 0;

        ans = max(ans , mj(a1x,a1y,b1x,b1y,c1x,c1y));

        ans = max(ans , mj(a2x,a2y,b1x,b1y,c1x,c1y));

        ans = max(ans , mj(a1x,a1y,b2x,b2y,c1x,c1y));

        ans = max(ans , mj(a1x,a1y,b1x,b1y,c2x,c2y));

        ans = max(ans , mj(a2x,a2y,b1x,b1y,c2x,c2y));

        ans = max(ans , mj(a1x,a1y,b2x,b2y,c2x,c2y));

        ans = max(ans , mj(a2x,a2y,b2x,b2y,c1x,c1y));

        ans = max(ans , mj(a2x,a2y, b2x,b2y, c2x,c2y));

        printf("%.10f",ans);
    }
    return 0;
}

 

 

C - Candy division

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
    int T;
    LL n;
    cin >> T;
    while(T--){
        cin >> n;
        if(n % 3 == 0){
            LL t = n / 3;
            cout << t << " " << t << " " << t << endl;
        }else if(n % 4 == 0){
            cout << (n >> 1) << " " << (n >> 2) << " " << (n >> 2) << endl;
        }else cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

 

D - Effective network

 

#include<bits/stdc++.h>
using namespace std;
int head[10010],cnt=0,maxlen,vis[10010],n,m,k;
struct e{
    int next,to;
}edge[100010];
void add(int a,int b)
{
    edge[++cnt].to=b;
    edge[cnt].next=head[a];
    head[a]=cnt;
}
bool bfs(int x)
{
    bool vis[10000]={0};
    queue<pair<int,int> > q;
    q.push(make_pair(x,0));
    vis[x]=1;
    while(!q.empty())
    {
        int u=q.front().first,step=q.front().second;
        q.pop();
        maxlen=max(step,maxlen);
        for(int i=head[u];i!=-1;i=edge[i].next)
        {
            int v=edge[i].to;
            if(!vis[v]){q.push(make_pair(v,step+1));vis[v]=1;}
        }
    }
}
int main()
{
    memset(head,-1,sizeof(head));
    cin>>n>>m>>k;
    for(int i=0;i<m;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        add(a,b);
        add(b,a);
    }
    for(int i=1;i<=n;i++)
    {
        bfs(i);
    }
    if(maxlen<=n-k)
    {
        printf("%d\n",n);
        for(int i=1;i<=n;i++) printf("%d ",i);
    }
    else printf("0\n");
}

 

 

E - Collection

 

#include <bits/stdc++.h>
using namespace std;

template<class T>
inline void read(T &ret){
    char c;
    int sign=1;
    while(c=getchar(),c!=-&&(c>9||c<0));
    if(c==-)sign=-1;
    else ret = c-0;
    while(c=getchar(),c>=0&&c<=9){
        ret = ret*10 + c-0;
    }
    ret*=sign;
}

int main(){
    int n;set<int> st;
    while(cin>>n){
        st.clear();
        int ans=0;
        for(int i=0;i<n;i++){
            int a;scanf("%d",&a);
            if(st.count(a))ans++;
            st.insert(a);
        }cout<<ans<<endl;
    }
    return 0;
}

 

 

 

F - Mattress Run 

 

 

J - Box Hedge

#include<bits/stdc++.h>
using namespace std;
int n,cnt=0,prelt[1001000],prert[1001000];
long long cir=0,sz=0,area=0;
struct row{
    int lt,rt,h;
}r[1001000];
struct point{
    int x,y;
}p[1001000];
bool cmp(point a,point b)
{
    return a.y<b.y;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&p[i].x,&p[i].y);
        p[i].y++;
    }
    sort(p,p+n,cmp);
    r[0].lt=r[0].rt=p[0].x;
    r[0].h=p[0].y;
    for(int i=1;i<n;i++)
    {
        if(r[cnt].h==p[i].y)
        {
            r[cnt].lt=min(r[cnt].lt,p[i].x);
            r[cnt].rt=max(r[cnt].rt,p[i].x);
        }
        else
        {
            cnt++;
            r[cnt].lt=r[cnt].rt=p[i].x;
            r[cnt].h=p[i].y;
        }
    }
    prelt[cnt]=r[cnt].lt;
    prert[cnt]=r[cnt].rt;
    for(int i=cnt-1;i>=0;i--) prelt[i]=min(prelt[i+1],r[i].lt);
    for(int i=cnt-1;i>=0;i--) prert[i]=max(prert[i+1],r[i].rt);
    area=1LL*(prert[0]-prelt[0]+1)*r[0].h;
    for(int i=1;i<=cnt;i++)
    {
        area=area+1LL*(prert[i]-prelt[i]+1)*(r[i].h-r[i-1].h);
    }
    sz=2LL*r[0].h;
    for(int i=1;i<=cnt;i++)
    {
        sz=sz+2LL*(r[i].h-r[i-1].h)+abs(prelt[i]-prelt[i-1])+abs(prert[i]-prert[i-1]);
    }
    sz+=((prert[cnt]-prelt[cnt]+3));
    cir=1LL*(prert[0]-prelt[0]+3)+2LL*(r[cnt].h+1);
    cout<<cir<<" "<<sz<<" "<<area<<endl;
    return 0;
}

 

K - ACM

 

#include <bits/stdc++.h>
using namespace std;

template<class T>
inline void read(T &ret){
    char c;
    int sign=1;
    while(c=getchar(),c!=-&&(c>9||c<0));
    if(c==-)sign=-1;
    else ret = c-0;
    while(c=getchar(),c>=0&&c<=9){
        ret = ret*10 + c-0;
    }
    ret*=sign;
}

int main(){
    string s;
    while(cin>>s){
        if(s.find("ACM")!=string::npos){
            puts("Fun!");
        } else puts("boring...");
    }
    return 0;
}

 

ACM-ICPC-Swiss-Subregional 2017 训练日志

标签:ext   puts   queue   run   tchar   effective   .com   get   chess   

原文地址:https://www.cnblogs.com/dowhile0/p/9190138.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!