[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 << '\n';
		}
	}
 
    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 << '\n';
			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 << '\n';
		if(used[arr[i].id])
			continue;
			
		if(arr[i].x == arr[i + 1].x)
		{
			cout << arr[i].id << ' ' << arr[i + 1].id << '\n';
			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 << '\n';
		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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值