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;
}