Codeforces Round #671 (Div. 2) (A~E)
Link~
题面差评,整场都在读题
A
根据奇偶性判断一下即可。
#include<bits/stdc++.h>
#define ll long long
#define N
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define lowbit(i) ((i)&(-i))
#define VI vector<int>
using namespace std;
int t,n;
string s;
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>t;
while(t--){
cin>>n;
cin>>s;
int odd,even;odd = even = -1;
if(n&1){
rep(i,0,n-1){
if((i&1)==0){
int v = s[i]-'0';
if(v&1) odd = 1;
else even = 1;
}
}
if(odd != -1) puts("1");
else puts("2");
}else{
rep(i,0,n-1){
if((i&1)==1){
int v = s[i]-'0';
//cout << "v: " <<v << endl;
if(v&1) odd = 1;
else even = 1;
}
}
if(even != -1) puts("2");
else puts("1");
}
}
return 0;
}
B
神必题意,读了快半小时才明白题意。
看着题目给的图的找个规律就行了。
#include<bits/stdc++.h>
#define int long long
#define N 1000015
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define lowbit(i) ((i)&(-i))
#define VI vector<int>
using namespace std;
int t,n,x,val[N];
int qpow(int a,int b){
int res = 1;
while(b){
if(b&1) res = res*a;
a = a*a;
b>>=1;
}
return res;
}
signed main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>t;n = 31;
rep(i,1,n) val[i] = val[i-1]*2+qpow(4,i-1);
rep(i,1,n) val[i] += val[i-1];//,cout << val[i] << endl;
while(t--){
cin>>x;
int l = 1,r = n,ans = 0;
while(l+3 < r){
int mid = (l+r)>>1;
if(val[mid] <= x) l = mid;
else r = mid;
}
rep(i,l,r){
if(val[i] <= x) ans = max(ans,i);
}
cout << ans << endl;
}
return 0;
}
C
大力分类讨论题,WA了好多发
#include<bits/stdc++.h>
#define int long long
#define N 1005
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define lowbit(i) ((i)&(-i))
#define VI vector<int>
using namespace std;
int t,n,a[N];
signed main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>t;
while(t--){
int ans = inf,cur,ff = 0;
cin>>n>>cur;
rep(i,1,n) cin>>a[i];
int sum = 0;rep(i,1,n) sum += a[i];
rep(i,1,n) if(a[i] == cur) ff++;
if(n*cur == sum) ans = min(ans,1ll);
if(ff == n) ans = min(ans,0ll);
if(ff > 1){
ans = min(ans,1ll);
}else{
ans = min(ans,2ll);
}
int left = n-ff;
if(left < n) ans = min(ans,1ll);
if(sum%n == 0){
if(ff) ans = min(ans,1ll);
}
cout << ans << endl;
}
return 0;
}
D
贪心构造
#include<bits/stdc++.h>
#define ll long long
#define N 100015
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define lowbit(i) ((i)&(-i))
#define VI vector<int>
using namespace std;
int n,a[N],b[N];
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>n;
rep(i,1,n) cin>>a[i];
sort(a+1,a+n+1);int l = 1,r = n/2+1;
rep(i,1,n){
if(i&1) b[i] = a[r++];
else b[i] = a[l++];
}
int cnt = 0;
rep(i,2,n-1){
if(b[i] < b[i-1]&&b[i] < b[i+1]) cnt++;
}
cout << cnt << endl;
rep(i,1,n) cout << b[i] << ' ';
return 0;
}
E
特判\(n = p*q\)的情况,其中\(p,q\)是质数,答案为\(1\),直接输出即可。
否则答案为零,
这样围成一个圈就行了。
垃圾场,让人挺不爽的,因为奇怪的原因被区分,可能是手速和英语不太行。
Codeforces Round #671 (Div. 2) (A~E)的更多相关文章
- Codeforces Round #316 (Div. 2) (ABC题)
A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序) ...
- Codeforces Round #240 (Div. 2)(A -- D)
点我看题目 A. Mashmokh and Lights time limit per test:1 secondmemory limit per test:256 megabytesinput:st ...
- Codeforces Round #324 (Div. 2) (哥德巴赫猜想)
题目:http://codeforces.com/problemset/problem/584/D 思路: 关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和. 关于奇数的哥德巴赫猜想:任一 ...
- Codeforces Round #395 (Div. 2)(未完)
2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> ...
- B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)
---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integ ...
- 【Codeforces】Codeforces Round #491 (Div. 2) (Contest 991)
题目 传送门:QWQ A:A - If at first you don't succeed... 分析: 按照题意模拟 代码: #include <bits/stdc++.h> usin ...
- 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)
题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
随机推荐
- 本地TOMCAT启动打包项目(WAR)
首先打个包,右击项目-->Export... 选择WEB-->WAR file-->Next 选个放置地址,勾选红框处-->finish 找到自己的tomcat目录 ...
- Docker下配置KeepAlive支持nginx高可用
案例子任务一.安装配置keepalived 步骤1:使用nginx镜像生成nginx-keep镜像 1) 启动nginx容器并进入 docker run -d --privileged nginx / ...
- 解决threadLocal父子变量传递问题
一.问题的提出 在系统开发过程中常使用ThreadLocal进行传递日志的RequestId,由此来获取整条请求链路.然而当线程中开启了其他的线程,此时ThreadLocal里面的数据将会出现无法获取 ...
- JVM初始化类契机
* 对于初始化只有主动使用类字段时才会初始化<br> * 除非对一个类的主动引用,否则所有引用类的方式都不会触发其初始化<br> * 主动引用有且只有以下场景:<p> ...
- flume的一些使用
一.第一层采集通道的编写 1.第一层采集脚本Source的选择①Source: 数据源在日志文件中! 读取日志中的数据,可以使用以下Source ExecSource: 可以执行一个linux命令,例 ...
- MFC3 基本对话框的使用(三) 滑块与进度条(sdnu)(C++大作业)
一.完成界面 运行前: 运行后: 二.工具 (1)滑块 (2)进度条 (3)文本框 (4)文本示例 (5)按钮 三.添加变量 四.添加事件 右键单击主对话框空白部分,打开类向导,选择"消息& ...
- DHCP.md
DHCP 主配置文件 从 /usr/share/doc/dhcp 复制 dhcpd.conf.sample 到/etc/dhcp下 ...
- 算法设计与分析 - 主定理Master theorem (分治法递推时间复杂度)
英文原版不上了 直接中文 定义 假设有递推关系式T(n)=aT(n/b)+f(n) 其中n为问题规模 a为递推的子问题数量 n/b为每个子问题的规模(假设每个子问题的规模基本一样) f(n)为递推以外 ...
- 【MySQL 基础】MySQ LeetCode
MySQL LeetCode 175. 组合两个表 题目描述 表1: Person +-------------+---------+ | 列名 | 类型 | +-------------+----- ...
- 【JavaWeb】Cookie&Session
Cookie&Session Cookie 什么是 Cookie Cookie 即饼干的意思 Cookie 是服务器通知客户端保存键值对的一种技术 客户端有了 Cookie 后,每次请求都发送 ...