• [Codeforces] Global Round 5 A C1 C2 D


    A题意:使得全部数初二上取整或下取整加和后

    用python取整输出就行

    import math
     
    n = int(input())
     
    cnt = 0
     
    while n :
     
        x = int(input())
     
        if x & 1:
            if cnt & 1:
                print( math.floor(x / 2) )
            else:
                print( math.ceil(x / 2) )
            cnt = cnt + 1
        else:
            print(x // 2)
     
     
        n = n - 1
    

    C1 空间存在一堆点 求一个删点顺序使得 每次删的点对中不包含其他点

    n方暴力求距离, 最小的距离的点对肯定不包含其他点

    然后删除标记即可

    #include <bits/stdc++.h>
    using namespace std;
    const int MAXN = 5e6 + 10;
    typedef long long ll;
    typedef long double ld;
    const ll MOD = 1e9 + 7;
    const int MX = 1e5 + 7;
     
    struct node
    {
    	ld x, y, z;
    }arr[MAXN];
     
    struct pdis
    {
    	int x, y;
    	ld dis;
    	bool operator < (const pdis b) const 
    	{
    		return dis < b.dis;
    	}
    }brr[MAXN];
     
    bool used[MAXN] = {0};
     
    ld get(int x, int y)
    {
    	return sqrt((arr[x].x - arr[y].x) * (arr[x].x - arr[y].x) +
    		(arr[x].y - arr[y].y) * (arr[x].y - arr[y].y) + 
    		(arr[x].z - arr[y].z) * (arr[x].z - arr[y].z)
    	);
    }
     
    int main()
    { 
    	//ios::sync_with_stdio(0);
    	//cin.tie(0); cout.tie(0);
    	//freopen("1.txt", "r", stdin);
    	
    	int n, p = 0;
    	
    	cin >> n;
    	
    	//注意空间
    	 
    	for(int i = 0; i < n; ++i)
    	{
    		cin >> arr[i].x >> arr[i].y >> arr[i].z;
    	}
    	
    	for(int i = 0; i < n; ++i)
    	{
    		for(int j = i + 1; j < n; ++j)
    		{
    			brr[p++] = pdis{i, j, get(i, j)}; 
    		}
    	}
    	
    	sort(brr, brr + p);
    	
    	for(int i = 0; i < p; ++i)
    	{
    		if(!used[brr[i].x] && !used[brr[i].y])
    		{
    			used[brr[i].x] = 1;
    			used[brr[i].y] = 1;
    			cout << brr[i].x + 1 << ' ' << brr[i].y + 1 << '
    ';
    		}
    	}
     
        return 0;
    }

    C3 数据范围增加到5e4 n方过不了

    从一维考虑,如果按从左到右的顺序删除点对,肯定不想交

    从二维考虑,如果把x固定 y就又变成一维了

    三维同上, 所以先删x y相同 z不同的点对

    删完 x y 就没了 删剩一个就说明成二维了

    然后在固定x删y

    最后删x

    复杂度

    3 * n * log(n)

    #include <bits/stdc++.h>
    using namespace std;
    const int MAXN = 5e6 + 10;
    typedef long long ll;
    typedef long double ld;
    const ll MOD = 1e9 + 7;
    const int MX = 1e5 + 7;
     
    struct node
    {
    	int id;
    	int x, y, z;
    	bool operator < (const node b) const 
    	{
    		if(x != b.x) return x < b.x;
    		if(y != b.y) return y < b.y;
    		return z < b.z;
    	}
    }arr[MAXN];
     
    bitset <MAXN> used;
     
    int p;
     
    void reget()
    {
    	int len = p;
    	p = 0;
    	for(int i = 0; i < len; ++i)
    	{
    		if(!used[arr[i].id])
    		{
    			arr[p++] = arr[i];
    		}
    	}
    }
     
    int main()
    { 
    	//ios::sync_with_stdio(0);
    	//cin.tie(0); cout.tie(0);
    	//freopen("1.txt", "r", stdin);
    	
    	cin >> p;
    	 
    	for(int i = 0; i < p; ++i)
    	{
    		arr[i].id = i + 1;
    		cin >> arr[i].x >> arr[i].y >> arr[i].z;
    	}
    	
    	sort(arr, arr + p);
    	
    	for(int i = 0; i < p - 1; ++i)
    	{
    		if(used[arr[i].id])
    			continue;
    			
    		if(arr[i].x == arr[i + 1].x && arr[i].y == arr[i + 1].y)
    		{
    			cout << arr[i].id << ' ' << arr[i + 1].id << '
    ';
    			used[arr[i].id] = 1; used[arr[i + 1].id] = 1;
    		}
    	}
    	
    	reget();
    	
    	sort(arr, arr + p);
    	
    	used.reset();
    	
    	for(int i = 0; i < p - 1; ++i)
    	{
    		//cout << arr[i].x << ' ' << arr[i].y << ' ' << arr[i].z << '
    ';
    		if(used[arr[i].id])
    			continue;
    			
    		if(arr[i].x == arr[i + 1].x)
    		{
    			cout << arr[i].id << ' ' << arr[i + 1].id << '
    ';
    			used[arr[i].id] = 1; used[arr[i + 1].id] = 1;
    		}
    	}
    	
    	reget();
    	
    	sort(arr, arr + p);
    	used.reset();
    	
    	for(int i = 0; i < p - 1; ++i)
    	{
    		if(used[arr[i].id])
    			continue;
    		cout << arr[i].id << ' ' << arr[i + 1].id << '
    ';
    		used[arr[i].id] = 1; used[arr[i + 1].id] = 1;
    	}
    	
    	
     
        return 0;
    }

    D - Balanced Playlist

    题意:从每个位置开始往右走,下一个位置大于当前走过区间的最大值的一半就能走

    考虑对于1点假如能走到5 则 2 3 4 都能走到5 状态是可以延续的

    那么用mutiset 维护当前点能走到最远的点

    当前点走过以后删掉当前点继续按状态往右维护 最后输出即可 注意循环数组要开三倍

    /*
        Zeolim - An AC a day keeps the bug away
    */
       
    //#pragma GCC optimize(2)
    //#pragma GCC ("-W1,--stack=128000000")
    #include <bits/stdc++.h>
    using namespace std;
    #define mp(x, y) make_pair(x, y)
    #define fr(x, y, z) for(int x = y; x < z; ++x)
    #define pb(x) push_back(x)
    #define mem(x, y) memset(x, y, sizeof(x))
    typedef long long ll;
    typedef unsigned long long ull;
    typedef long double ld;
    typedef std::pair <int, int> pii;
    typedef std::vector <int> vi;
    //typedef __int128 ill;
    const ld PI = acos(-1.0);
    const ld E = exp(1.0);
    const ll INF = 0x3f3f3f3f;
    const ll MOD = 1e9 + 7;
    const int MAXN = 2e6 + 10;
     
    int n;
     
    int arr[MAXN] = {0};
    int ans[MAXN] = {0};
     
    int main()
    {
        ios::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
        //freopen("1.txt", "r", stdin);
     	
     	cin >> n;
     	
     	int mx = -1, mi = INF;
     	for(int i = 0; i < n; ++i)
     	{
     		cin >> arr[i];
     		mx = max(arr[i], mx);
     		mi = min(arr[i], mi);
    	}
    	
    	if(mx / 2.0 <= ld(mi) )
    	{
    		for(int i = 0; i < n; ++i)
    			cout << "-1 ";
    		return 0;
    	}
    	
    	for(int i = n; i < n * 3; ++i)
    	{
    		arr[i] = arr[i % n];
    	}
        
        multiset <int> ST;
        
        int r = 1;
        
        for(int i = 0; i < n; ++i)
        {
        	if(ST.size() == 0)
        		ST.insert(arr[i]), r = i + 1;
        	while(arr[r] >= *(--(ST.end())) / 2.0)
        	{
        		ST.insert(arr[r++]);
    		}
    		ans[i] = ST.size();
    		auto it = ST.lower_bound(arr[i]);
    		ST.erase(it);
    	}
    	
    	for(int i = 0; i < n; ++i)
    	{ cout << ans[i] << ' '; }
    	
        return 0;
    }
  • 相关阅读:
    89、Beego框架(上)——2020年07月30日22:05:40
    88、go框架有哪些-转载——2020年07月30日12:56:43
    86、go语言优势-转载——2020年07月27日16:08:04
    85、go开发配置环境——2020年07月27日13:08:27
    84、Linux命令——2020年07月27日12:51:44
    83、Linux知识-系统介绍、文件系统、远程操作——2020年07月27日12:47:14
    82、《给年轻人的极简金融课》-童哲——2020年7月23日20:17:49
    81、nodejs学习——2020年07月22日13:30:25
    无法启动此程序,因为计算机中丢失VCRUNTIME140.dll 尝试重新安装此程序以解决此问题
    关于js单页面实现跳转原理以及利用angularjs框架路由实现单页面跳转
  • 原文地址:https://www.cnblogs.com/zeolim/p/12270325.html
Copyright © 2020-2023  润新知