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 ... 
随机推荐
- Linux系统在IT行业处于什么位置
			相信每一位程序员对于linux都不陌生,不管是新入行的小白,还是有着十几年编程经验的大佬,都知道Linux在IT行业中的位置吧! 我是一名Web JAVA开发的小白,对于初入IT行业的小白来说,工 ... 
- 【 JdbcUtils  】mysql数据库查询
			JdbcUtils package k.util; import java.sql.*; import java.util.ArrayList; import java.util.HashMap; i ... 
- 【PAT甲级】1038 Recover the Smallest Number (30 分)
			题意: 输入一个正整数N(<=10000),接下来输入N个字符串,每个字符串包括至多8个字符,均为数字0~9.输出由这些字符串连接而成的最小数字(不输出前导零). trick: 数据点0只包含没 ... 
- Dubbo+zookeeper部署到tomcat上注意事项,遇到的问题,闪退,运行报错等
			需要下载工具zookeeper-3.4.14.tar.gz,dubbo-2.5.x.zip,apache-tomcat-8.5.47-windows-x64.zip这些官网都可以先下载到 1.最新的z ... 
- Python作业篇 day04
			###一.写代码,有如下列表,按照要求实现每一个功能 li=['alex','bibi','cc0','didi'] #1.计算列表的长度 #2.列表中追加元素'seven',并输出添加后的列表 #3 ... 
- S7-300 与TP900 组态 棒图 量表 滚动条 滚动条设置的值通过IO输出域显示出来
			切换编程语言 注意 一定要 先选中 某一个组织块 例如 OB1 然后单击 菜单 编辑 切换编程语言 组态 300 PLC 的CPU 点击 SIMENSE LOGO 查看 循环 中断 OB35 可以 在 ... 
- 解决css中display:inline-block产生的空隙问题
			<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ... 
- 百度统计数据导出demo的坑
			1.用户名中文的问题 由于demo文件格式的问题,如果用户名使用中文的话,会出现一下问题 ----------------------preLogin---------------------- [ ... 
- Day3-P - Matrix POJ3685
			Given a N × N matrix A, whose element in the i-th row and j-th column Aij is an number that equals i ... 
- Thymeleaf--起步
			Spring官方支持的服务的渲染模板中,并不包含jsp.而是Thymeleaf和Freemarker等,而Thymeleaf与SpringMVC的视图技术,及SpringBoot的自动化配置集成非常完 ... 
