zoukankan      html  css  js  c++  java
  • 2019省赛补题

    Game on a Graph

    https://zoj.pintia.cn/problem-sets/91827364500/problems/91827370511

    题目大意。有两队人,一队是1,一队是2,两队混着站在一排。给一张n个点,m条边的图。那一排人可以一次拿走一条边,每次拿走都尽量不破坏这张图,就是说它还是张图,若轮到某人取出某条边,图恰好坏了,那么另一个队就赢了。输出赢的那个队。

    思路:

      考察图的性质,n个点最多有n-1条边。所以我们可以确定第m - ( n - 1) 个人拿中第n-1条边,该队输。考虑到m - (n-1)  可能大于总人数, 所以结果应该对人数取模。

    #include <bits/stdc++.h>
    
    using namespace std;
    const int N = 1e5 + 10;
    int t, k, n, m;
    char team[N];
    
    int main()
    {
    	scanf("%d", &t);
    	while(t--){
    		int s;
    		scanf("%d%s%d%d",&s, team, &n, &m);
    		for(int i = 1;i <= m; ++ i){
    			int x, y;
    			scanf("%d%d", &x, &y);
    		}
    		printf("%c
    ", team[(m - n + 1)%s] == '1' ? '2' : '1');
    	}
    }
    

    Tokens on the Segments 

    https://zoj.pintia.cn/problem-sets/91827364500/problems/91827370515

     这样贪心也能过 ...

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 100010;
    
    struct node{
    	int l, r;
    };
    
    bool cmp(node a, node b){
    	if(a.l == b.l){
    		return a.r < b.r;
    	}
    	return a.l < b.l;
    }
    node a[N];
    map<int, bool> mp;
    int t, n, cnt;
    int main()
    {
    	scanf("%d", &t);
    	while(t--){
    		map<int, bool>::iterator it = mp.begin();
    		
    		for(;it!=mp.end();it++){
    			it->second = false;
    		}
    		
    		cnt = 0;
    		scanf("%d", &n);
    		for(int i = 1;i <= n; ++ i){
    			scanf("%d%d", &a[i].l, &a[i].r);
    		}
    		
    		sort(a + 1, a + 1 + n, cmp);
    			
    		for(int i = n; i >= 1; -- i){
    			for(int j = a[i].r;j >= a[i].l; -- j){
    				if(!mp[j]) {
    					mp[j] = true;
    					cnt ++;
    					break;
    				}
    			}
    		}
    			
    		printf("%d
    ", cnt);
    	}
    }
    

      

  • 相关阅读:
    geoserver发布mysql表数据
    geoserver1
    geoserver
    快速搭建arcgis以及cesium环境
    openlayers和cesium实现地图二三维切换
    记Mysql类型引起的BUG
    OpenLayers 图层(Layers) 详解
    基于TrueLicense实现产品License验证功能
    第七章
    第六周进度报告
  • 原文地址:https://www.cnblogs.com/DefineWaAc/p/13758007.html
Copyright © 2011-2022 走看看