QFNU-ACM 2020.9.27组队赛 2019山东省赛复现 补题

4116 Game on a Graph

给出n个点,m条边,m条边一定连通,两组人依照一定次序取走一些边,取走之后,图形不连通的就输了

即取走n-1条边的队伍输掉

英语看不懂啊啊啊QWQ

#include <bits/stdc++.h>
using namespace std;
int main()
{
   int t;
   cin>>t;
   while(t--){
     int n,a,i,x,y;
     string s;
     cin>>n>>s;
     cin>>x>>y;
     for(i=0;i<y;i++){
        cin>>a>>a;
     }
     y=(y-x+1)%n;
     if(s[y]=='1'){
        cout<<2<<endl;
     }else{
        cout<<1<<endl;
     }
   }
}

 4120 Tokens on the Segments

给出N条线段,(l,r),每个整数点都可以被标记,但被标记的坐标不能相同,求至少有一个点被标记的点有多少

先对所有线段按左端点从小到大,左端点相同时按右端点从小到大的顺序进行排序

队首线段左端点可标记则出队,ans++,

若队首线段左端点已被标记,则将该线段左端点加一后再入队(之后再看看能不能标记W)

 

我的脑子里没有队列

参考大佬代码

 

#include <bits/stdc++.h>
using namespace std;
class segment{
public:
    int l,r;
    bool operator<(segment a)const{
    if(l==a.l){
        return r>a.r;
    }
    return l>a.l;

    }
};
priority_queue<segment> q;
int main()
{
    int t,n,i;
    cin>>t;
    segment m;
    while(t--)
    {
        cin>>n;
        for(i=0; i<n; i++)
        {
            cin>>m.l>>m.r;
            q.push(m);
        }
        long long h=0,ans=0;
        while(!q.empty())
        {
            segment a=q.top();
            q.pop();
            if(a.l==h)
            {
                a.l++;
                if(a.l<=a.r)
                    q.push(a);
            }
            else
            {
                h=a.l;
                ans++;

            }
        }
    cout<<ans<<endl;
    }
}

 

posted @ 2020-10-04 11:35  一只幽灵飘过  阅读(62)  评论(0编辑  收藏  举报