NOIP2016 暑期培訓 D5

今天的題

wait?!
我之前明明寫好了這篇文章
哪去了?!

好吧,迴歸正題
今天的題腦洞有點大


第一題
莫名其妙的推出了奇怪的性質
然而考試時整個人是傻逼的
寫了一個能過的暴力模擬
然而寫掛了
後經改正
過了?!
大大提高了整個人的代碼實現能力
學會了新姿勢
坑爹的
這博客掛了
我的代碼太長了?!
好的
他恢復了
那麼繼續
map在定義時可以:

std::map <key_type,value_type,compare_type> mymap;

傳入第三個參數
以結構體重載小括號
達到使該map用該重載方式排序的效果

#include <cstdio>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
int n,idx;
struct edge
{
    int a,b;
    bool operator <(const edge &s)const
    {
        if(a==s.a)
            return b<s.b;
        return a<s.a;
    }
    bool operator ==(const edge &s)const
    {
        return a==s.a && b==s.b;
    }
};
struct tri
{
    edge e[3];
    int d;
    bool operator <(const tri &s)const
    {
        if(d==s.d)
        {
            if(e[0].a==s.e[0].a)
            {
                if(e[0].b==s.e[0].b)
                {
                    if(e[1].a==s.e[1].a)
                        return e[1].b<s.e[1].b;
                    return e[1].a<s.e[1].a;
                }
                return e[0].b<s.e[0].b;
            }
            return e[0].a<s.e[0].a;
        }
        return d<s.d;
    }
    bool operator ==(const tri &s)const
    {
        return e[0]==s.e[0] && e[1]==s.e[1];
    }
    bool operator !=(const tri &s)const
    {
        return !(*this==s);
    }
};
struct abcd
{
    tri id[2];
    int c;
};
struct node
{
    tri to;
    int next;
}data[100000];
struct tc
{
    bool operator ()(const tri &b1,const tri &b2)const
    {
        if(b1.e[0].a==b2.e[0].a)
        {
            if(b1.e[0].b==b2.e[0].b)
            {
                if(b1.e[1].a==b2.e[1].a)
                    return b1.e[1].b<b2.e[1].b;
                return b1.e[1].a<b2.e[1].a;
            }
            return b1.e[0].b<b2.e[0].b;
        }
        return b1.e[0].a<b2.e[0].a;
    }
};
map <tri,int,tc> head,cnt;
map <edge,abcd> emap;
map <tri,bool,tc> v,del;
priority_queue <tri> q;
tri t[50000],fat;
void add(tri a,tri b)
{
//  printf("?%d",head[a]);
    data[++idx].to=b;
    data[idx].next=head[a];
    head[a]=idx;
//  printf(" %d %d\n",idx,head[a]);
    return ;
}
void dfs(tri a,tri fa)
{
    if(v[a])
        return ;
    a.d=fa.d+1;
    v[a]=true;
    for(int i=0;i<3;i++)
        if(emap[a.e[i]].c==2)
        {
            cnt[a]++;
            if(v[emap[a.e[i]].id[1]])
                dfs(emap[a.e[i]].id[0],a);
            if(v[emap[a.e[i]].id[0]])
                dfs(emap[a.e[i]].id[1],a);
        }
    if(a!=t[0])
        add(a,fa);
    if(cnt[a]==1)
        q.push(a);
    return ;
}
bool bfs()
{
    int ans=0;
    while(!q.empty())
    {
        tri tmp=q.top();
        q.pop();
//      printf("%d\n",tmp.d);
        ans++;
        del[tmp]=true;
        cnt[tmp]--;
//      for(int i=0;i<3;i++)
//          printf("%d %d\n",tmp.e[i].a,tmp.e[i].b);
//      printf("\n");
//      printf("%d\n",head[tmp]);
        for(int i=head[tmp] ; i>0 ; i=data[i].next)
        {
//          for(int j=0;j<3;j++)
//              printf("!%d %d\n",data[j].to.e[j].a,data[j].to.e[j].b);
//          printf("a\n");
            cnt[data[i].to]--;
//          printf("%d\n",cnt[t[0]]);
            if(cnt[t[0]]==1)
                return (ans+1)&1;
            if(cnt[data[i].to]==1)
                q.push(data[i].to);
        }
    }
    printf("!");
    return ans&1;
}
int main()
{
    freopen("A.in","r",stdin);
    freopen("A.out","w",stdout);
    scanf("%d",&n);
    for(int i=0;i<n-2;i++)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        t[i].e[0].a=x;
        t[i].e[0].b=y;
        t[i].e[1].a=x;
        t[i].e[1].b=z;
        t[i].e[2].a=y;
        t[i].e[2].b=z;
        if(t[i].e[0].a>t[i].e[0].b)
            swap(t[i].e[0].a,t[i].e[0].b);
        if(t[i].e[1].a>t[i].e[1].b)
            swap(t[i].e[1].a,t[i].e[1].b);
        if(t[i].e[2].a>t[i].e[2].b)
            swap(t[i].e[2].a,t[i].e[2].b);
//      printf("%d %d\n",t[i].e[0].a,t[i].e[0].b);
        emap[t[i].e[0]].id[emap[t[i].e[0]].c++]=t[i];
        emap[t[i].e[1]].id[emap[t[i].e[1]].c++]=t[i];
        emap[t[i].e[2]].id[em
[2]].c++]=t[i];
    }
/*  for(int i=0;i<n-2;i++)
    {
        for(int j=0;j<3;j++)
            printf("%d ",emap[t[i].e[j]].c);
        printf("\n");
    }*/
    dfs(t[0],fat);
    if(cnt[t[0``
``## 標題 #``````

==1)
    {
        printf("TAK");
        fclose(stdin);
        fclose(stdout);
        return 0;
    }
    if(bfs())
        printf("TAK");
    else
        printf("NIE");
    fclose(stdin);
    fclose(stdout);
    return 0;
}

```1)
    {
        printf("TAK");
        fclose(stdin);
        fclose(stdout);
        return 0;
    }
    if(bfs())
        printf("TAK");
    else
        printf("NIE");
    fclose(stdin);
    fclose(stdout);
    return 0;
}


我的
博客
活過來了
好的
繼續看第二題
聽說也是一道思博

我沒想到
遞推拆分
可以用平衡樹維護



這麼愉快就到了第三題
線段樹
維護上下兩個區間
好棒啊
然後考試時就被思博啦


大爺的題就這麼結束了麼。。。
好吧
結束了

發佈了35 篇原創文章 · 獲贊 5 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章