Codeforces Round #618 (Div. 2) 小号上紫之路
这一场涨了不少,题也比较偏思维,正好适合我
A. Non-zero
我们记录这些数字的总和sum,并且记录0的个数zero,显然答案应该是这些0的个数,注意如果sum+zero==0的话答案要额外加一(因为总和不能是0)
#include<bits/stdc++.h>
#define LL long long
#define maxn 100010
#define x first
#define y second
using namespace std; typedef pair<int, int> pii; int a[maxn]; int main(){
int T;
cin >> T;
while(T--){
int n, sum = ;
int z = ;
cin >> n;
for(int i = ; i < n; ++i){
cin >> a[i];
sum = sum + a[i];
if(a[i] == ){
z++;
}
}
int ans = ;
if(sum == ){
ans = ;
sum++;
}
if(z != ){
ans = max(ans, z);
if(sum == ){
sum = sum + ans - ;
}
else{
sum = sum + ans;
}
}
if(sum == ){
ans++;
}
cout << ans << endl;
}
return ;
}
B. Assigning to Classes
要使得两组的中位数相差最小,很显然,如果把两组表示为G1和G2,那么如果G1的中位数更靠前,那么G2的中位数一定更靠后,那么易得当这俩中位数靠的最近的时候相差最小,此时G1跟G2的中位数应该在数组的中间,直接排序输出数组中间的差值便是答案
#include<bits/stdc++.h>
#define LL long long
#define maxn 100010
#define inf 0x3f3f3f3f
#define x first
#define y second
using namespace std; typedef pair<int, int> pii; int a[maxn << ]; int main(){
int T;
cin >> T;
while(T--){
int n;
cin >> n;
for(int i = ; i < * n; ++i){
cin >> a[i];
}
sort(a, a + * n);
int n1, n2;
if(n % ){
cout << a[n] - a[n - ] << endl;
}
else{
cout << a[n] - a[n - ] << endl;
}
}
return ;
}
C. Anu Has a Function
我们考虑下这一组式子,对于f(a, b)=(a|b)-b函数的结果c的每一二进制位,如果这一位上b是1,那么容易知道c这一位一定是0,否则c这一位是看a这一位是否为1,很显然,c的二进制上为1的位一定是a这一位为1,b这一位为0的地方。所以推广到很多个b,就是a这一位为1,很多个b那一位全是0的时候,答案这一位才是0,取最大值就行了,我的处理方式还是比较简单的。
#include<bits/stdc++.h>
#define LL long long
#define maxn 100010
#define inf 0x3f3f3f3f
#define x first
#define y second
using namespace std; typedef pair<int, int> pii; int a[maxn]; int bit[]; void _in(int num){
int now = ;
while(num){
if(num & ){
bit[now]++;
}
num = num >> ;
now++;
}
} int _out(int num){
int now = , ret = ;
while(num){
if(num & && bit[now] == ){
ret = ret + ( << now);
}
num = num >> ;
now++;
}
return ret;
} int main(){
int n;
cin >> n;
memset(bit, , sizeof bit);
for(int i = ; i < n; ++i){
cin >> a[i];
_in(a[i]);
}
int ma = , no = -;
for(int i = ; i < n; ++i){
if(_out(a[i]) > ma){
ma = _out(a[i]);
no = i;
}
}
if(no >= ){
cout << a[no] << " ";
}
for(int i = ; i < n; ++i){
if(i != no){
cout << a[i] << " ";
}
}
cout << endl;
return ;
}
D. Aerodynamic
题意挺麻烦的,但是结论却很简单,必须是中心对称的偶数边数的多边形,我的处理方式居然没被hack,神奇
#include<bits/stdc++.h>
#define LL long long
#define maxn 100010
#define inf 0x3f3f3f3f
#define x first
#define y second
using namespace std; typedef pair<double, double> pdd; pdd a[maxn]; pdd b[maxn]; int main(){
int n;
cin >> n;
for(int i = ; i < n; ++i){
cin >> a[i].x >> a[i].y;
if(i > ){
b[i].x = a[i].x - a[i - ].x;
b[i].y = a[i].y - a[i - ].y;
}
}
b[].x = a[].x - a[n - ].x;
b[].y = a[].y - a[n - ].y;
sort(b, b + n);
if(n % ){
cout << "NO" << endl;
return ;
}
bool ans = true;
for(int i = ; i < n; ++i){
if(b[i].x + b[n - i - ].x != || b[i].y + b[n - i - ].y != ){
ans = false;
}
}
cout << (ans ? "YES" : "NO") << endl;
return ;
}
E. Water Balance
最后这个题听学长说是单调栈,还是比较简单明了的写法,但是我没写出来,可惜了
注意这个题取12位小数会WA,一定要取8位小数
这一场排到了576名,rating到了1700+,但是如果没有傻卵错误其实还可以再往前排一点,希望再打几场能上紫名 。
Codeforces Round #618 (Div. 2) 小号上紫之路的更多相关文章
- Codeforces Round #618 (Div. 2)
题库链接 https://codeforces.ml/contest/1300 A. Non-zero 一个数组,每次操作可以给某个数加1,让这个数组的积和和不为0的最小操作数 显然如果有0的话,必须 ...
- Codeforces Round #618 (Div. 1)A(观察规律)
实际上函数值为x&(-y) 答案仅和第一个数字放谁有关 #define HAVE_STRUCT_TIMESPEC #include <bits/stdc++.h> using na ...
- Codeforces Round #618 (Div. 2)C. Anu Has a Function
Anu has created her own function ff : f(x,y)=(x|y)−y where || denotes the bitwise OR operation. For ...
- [CF百场计划]#2 Codeforces Round #618 (Div. 2)
A. Non-zero Description: Guy-Manuel and Thomas have an array \(a\) of \(n\) integers [\(a_1, a_2, \d ...
- Codeforces Round #618 (Div. 1)C(贪心)
把所有数看作N块,后面的块比前面的块小的话就合并,这个过程可能会有很多次,因为后面合并后会把前面的块均摊地更小,可能会影响更前面地块,像是多米诺骨牌效应,从后向前推 #define HAVE_STRU ...
- Codeforces Round #618 (Div. 1)B(几何,观察规律)
观察猜测这个图形是中心对称图形是则YES,否则NO #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace ...
- Codeforces Round #618 (Div. 2)A. Non-zero
Guy-Manuel and Thomas have an array aa of nn integers [a1,a2,…,an ]. In one step they can add 11 to ...
- Codeforces Round #618 (Div. 2)-B. Assigning to Classes
Reminder: the median of the array [a1,a2,-,a2k+1] of odd number of elements is defined as follows: l ...
- Codeforces Round #618 (Div. 2)-Non-zero
Guy-Manuel and Thomas have an array a of n integers [a1,a2,-,an]. In one step they can add 1 to any ...
随机推荐
- git rebase 与git merge 小结
git merge是用来合并两个分支的. $ git merge b 将b分支合并到当前分支 同样 $ git rebase b ,也是把 b分支合并到当前分支 ---------------- ...
- uniapp - 导航切换(样式)
<view class="text-area" v-for="(menu,i) in menus" :key="i" v-show=& ...
- Linux centosVMware PHP动态扩展模块
PHP动态扩展模块 /usr/local/php/bin/php -m //查看模块 下面安装一个redis的模块 cd /usr/local/src/ wget https://codeload.g ...
- bfc作用
作用 1.清浮动 2.不被浮动元素覆盖 3.阻止父子margin传递 触发条件: 1.float不为none 2.position不为static或relative 3.display:inline- ...
- SpringMVC 注解配置
使用注解配置spring mvc (1)spring mvc的配置文件 <?xml version="1.0" encoding="UTF-8"?> ...
- 等级保护2.0-oracle
- 无需密码攻击 Microsoft SQL Server
最近的一次渗透测试里,在我们捕获的一些数据包中发现了一些未经加密的 Microsoft SQL Server(MSSQL) 流量.起初,我们认为这样就可以直接嗅探到认证凭证,然而,MSSQL 加密了认 ...
- 移动硬盘在MAC找不着了
原因: 移动硬盘,还没有推出的时候,我就直接拔了,导致文件被损坏了. 在MAC系统下,试了很多命令,一不小心加载上了. 但是只读模式,此时我想应该是有损坏了,系统也提示要重新格式化,这个代价太大了,里 ...
- Oracle数据库自带了decode()函数
Oracle数据库自带了decode()函数,函数的使用方法如下: SELECT emp.ename, emp.job, emp.sal, decode(job, 'manager ...
- Day2-J-逃离迷宫-HDU-1728
给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位 ...