Codeforces 653C Bear and Up-Down【暴力】
题目链接:
http://codeforces.com/problemset/problem/653/C
题意:
给定序列,偶数位的数字比两边都大,则成为nice,只可以交换两个数字,问有多少种交换方式使得最后的序列为nice。
分析:
比赛的时候找规律,找呀找了好久都没看出来。。。。由于只可以交换一次,交换两个数字,所以最多改变的6个数字的关系。那么可以交换成nice的话,原来不满足的肯定很少,直接把这些数字提出来,然后暴力的和序列每个元素交换一下,看看其余不满足的是否变成满足就好啦~~~
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1500005;
int t[maxn];
vector<int>v;
typedef pair<int, int>pii;
map<pii, int>vis;
int n;
bool judge(int b)
{
if(b & 1) {
if(b < n - 1) return t[b - 1] < t[b] && t[b + 1] < t[b];
else return t[b - 1] < t[b];
}
else if(b > 0 && b < n - 1) return t[b - 1] > t[b] && t[b + 1] > t[b];
else if(b == 0) return t[b + 1] > t[b];
else return t[b - 1] > t[b];
}
int main (void)
{
cin>>n;
for(int i = 0; i < n; i++){
cin>>t[i];
}
for(int i =0; i < n; i += 2){
if(i == 0 && t[i] >= t[i + 1]){
v.push_back(i);v.push_back(i + 1);
}
if(i == n - 1 && t[i] >= t[ i - 1]){
v.push_back(i);v.push_back(i - 1);
}
else if(i > 0 && i < n - 1){
if( t[i] >= t[i + 1]){
v.push_back(i);v.push_back(i + 1);
}
else if(t[i] >= t[i - 1]){
v.push_back(i);v.push_back(i - 1);
}
else if( t[i] >= t[i + 1] && t[i] >= t[i - 1]){
v.push_back(i);v.push_back(i - 1);v.push_back(i + 1);
}
}
}
int cnt = 0;
if(v.size() > 10){
cout<<0<<endl;
return 0;
}
for(int i = 0; i < v.size(); i++){
for(int j = 0; j < n; j++){
if(t[j] != t[v[i]]){
swap(t[j], t[v[i]]);
bool ok = true;
for(int k = 0; k < v.size(); k++){
if(!judge(v[k])) ok = false;
}
if(!judge(j)) ok = false;
if(ok){
// cout<<t[i]<<' '<<t[j]<<endl;
pii p = pii(min(v[i], j),max(v[i],j));
if(!vis[p]){vis[p] = 1; cnt++;}
}
swap(t[v[i]], t[j]);
}
}
}
cout<<cnt<<endl;
return 0;
}
Codeforces 653C Bear and Up-Down【暴力】的更多相关文章
- Codeforces 791A Bear and Big Brother(暴力枚举,模拟)
A. Bear and Big Brother time limit per test:1 second memory limit per test:256 megabytes input:stand ...
- Codeforces 385C Bear and Prime Numbers
题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...
- Codeforces 385B Bear and Strings
题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...
- Codeforces 680D Bear and Tower of Cubes 贪心 DFS
链接 Codeforces 680D Bear and Tower of Cubes 题意 求一个不超过 \(m\) 的最大体积 \(X\), 每次选一个最大的 \(x\) 使得 \(x^3\) 不超 ...
- Codeforces 385C Bear and Prime Numbers(素数预处理)
Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...
- [Codeforces 639F] Bear and Chemistry (Tarjan+虚树)(有详细注释)
[Codeforces 639F] Bear and Chemistry(Tarjan+虚树) 题面 给出一个n个点,m条边的无向图(不保证连通,可能有自环和重边),有q次询问,每次询问给出p个点和q ...
- codeforces 653C C. Bear and Up-Down(乱搞题)
题目链接: C. Bear and Up-Down time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- codeforces 680E Bear and Square Grid 巧妙暴力
这个题是个想法题 先预处理连通块,然后需要用到一种巧妙暴力,即0变1,1变0,一列列添加删除 复杂度O(n^3) #include <cstdio> #include <iostre ...
- Codeforces Gym 100513M M. Variable Shadowing 暴力
M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...
随机推荐
- EMAC IP 核
在有线连接的世界里,以太网(Ethernet)无所不在.以太网具有各种速度模式.接口方式.以及灵活的配置方式.现在的以太网卡都是10/100/1000Mbps自适应网卡.以太网的物理层(PHY)通常使 ...
- -bash: mysql: command not found 之 MAC
第一次尝试: ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql 提示:Operation not permitted 再次,加sudo附上管理员权限,依旧 ...
- 【Hive】explain command throw ClassCastException in 2.3.4
参考:https://issues.apache.org/jira/browse/HIVE-21489 (一)问题描述: Hive-2.3.4 执行 explain select * from sr ...
- Linux一些常用小命令
使用xshell连接虚拟机 rz 上传的linux服务器 sz 从服务器上下载 df 查看磁盘大小 -h du 查看所有磁盘(硬盘)大小(-h 可读 -s统计当前目录的大小)du -sh free ...
- vscode vue template 下 style 的样式自动提示 #bug 这个搞完vue语法esLint就又不好使了,ERR
网上都是 "*.vue": "vue",改成"*.vue": "html" 就ok了 "files.ass ...
- tabsGif
tabsGif
- 暑假集训 || 树DP
树上DP通常用到dfs https://www.cnblogs.com/mhpp/p/6628548.html POJ 2342 相邻两点不能同时被选 经典题 f[0][u]表示不选u的情况数,此时v ...
- ideal取消按下两次shift弹出搜索框 修改idea,webstrom,phpstrom 快捷键double shift 弹出search everywhere
因为经常需要在中英文之间切换,所以时常使用shift键,一不小心就把这个Searchwhere 对话框调出来了,很是麻烦. 因此痛定思痛, 我决定将这个按两下shift键就弹出搜索框的快捷键禁用了! ...
- 企业支付宝账号开发接口教程--JAVA-UTF-8(实际操作完善中...SpringMVC+JSP)
关于即时到账的开发.审核通过.简单测试如下. 希望看的可以收藏或者赞一下哦. 1:拥有自己的支付宝企业账号.去产品商店选择适合自己的方案.并签约合同. 2:选择合适的商家收款产品并去签约.填写相应的信 ...
- tab bar controller
下面记一下怎样通过代码的方式为选项卡添加视图. 1.创建一个基于Empty Application的项目 2.创建两个新类,基类选择UIViewController,勾选With XIB for us ...