CodeForces - 995B Suit and Tie
明明可以出成n<=1e5但是因为拒绝写数据结构而只出到n<=100,,,出题人真的很棒棒。。
一个显然的贪心就是,把和当前序列最左端的数匹配的数移到它的右边,这样迭代下去总是最优的。
考虑到这样总不会比把这个数向右移到匹配的数左边更劣,而且每个数都得匹配。。。。
n<=100的话直接扫一下就行了,反正怎么做都可以过的数据范围。。。。
n再大一点的话上树状数组就行了。。。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=105; int n,a[N*2],ans,m; int main(){
scanf("%d",&n),m=n<<1;
for(int i=1;i<=m;i++) scanf("%d",a+i); for(int i=1,j;i<=m;i++) if(a[i]){
for(j=i+1;a[j]!=a[i];j++) ans+=(a[j]>0);
a[j]=0;
} printf("%d\n",ans);
return 0;
}
CodeForces - 995B Suit and Tie的更多相关文章
- CodeForces 995B Suit and Tie(贪心,暴力)
https://codeforces.com/problemset/problem/995/B 题意: 就是通过每次移动相邻的两位数,来使数值相同的数挨在一起,求最少要移动多少次. 思路: 直接从前往 ...
- code forces 996D Suit and Tie
D. Suit and Tie time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- CF995B Suit and Tie 贪心 第十三
Suit and Tie time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- [Codeforces Round #492 (Div. 1) ][B. Suit and Tie]
http://codeforces.com/problemset/problem/995/B 题目大意:给一个长度为2*n的序列,分别有2个1,2,3,...n,相邻的位置可以进行交换,求使所有相同的 ...
- 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)
题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...
- 越狱Season 1-Season 1, Episode 3: Cell Test
Season 1, Episode 3: Cell Test -CO: Oh, my God. 我的天 Williamson, get in here. Williamson 快进来 What the ...
- Daily record-November
November 11. I managed to grab her hand. 我抓到了她的手.2. He passed a hand wearily over his eyes. 他疲倦地用手抹了 ...
- 从零开始单排学设计模式「装饰模式」黑铁 I
阅读本文大概需要 3.6 分钟. 本篇是设计模式系列的第四篇,虽然之前也写过相应的文章,但是因为种种原因后来断掉了,而且发现之前写的内容也很渣,不够系统. 所以现在打算重写,加上距离现在也有一段时间了 ...
- [Python设计模式] 第6章 衣服搭配系统——装饰模式
github地址:https://github.com/cheesezh/python_design_patterns 题目 设计一个控制台程序,可以给人搭配嘻哈风格(T恤,垮裤,运动鞋)或白领风格( ...
随机推荐
- 【转载】VS2013安装需要IE10
因为需要移动办公,需要给笔记本搭建编程环境.安装VS2013时遇到了小麻烦,提示我,需要安装IE10. 然后我很听话的按照提供的超链接,到了官网,下载了最新的IE11,然后安装,结果告诉我下载的IE版 ...
- python学习笔记(五)数值类型和类型转换
Python中的数值类型有: 整型,如2,520 浮点型,如3.14159,1.5e10 布尔类型 True和False e记法: e记法即对应数学中的科学记数法 >>> 1.5e1 ...
- FileReader 与canvas结合使用显示图片
话不多少,直接上代码 function fileChange() { var file = this.files[0]; var imageType = /^image\//; //是否是图片 if ...
- bzoj 1093 缩点+DP
首先比较明显的是如果存在一个半连通子图,我们将其中的环缩成点,那么该图仍为半连通子图,这样我们就可以先将整张图缩点,重新构图,新图为拓扑图,记录每个新的点表示的强连通分量中点的个数num[i],那么我 ...
- Eureka服务续约(Renew)源码分析
主要对Eureka的Renew(服务续约),从服务提供者发起续约请求开始分析,通过阅读源码和画时序图的方式,展示Eureka服务续约的整个生命周期.服务续约主要是把服务续约的信息更新到自身的Eurek ...
- 利用itext将html转为pdf
亲测代码没有问题,需要注意细节已经标注:需要jar包:iText-2.0.8.jar:core-renderer-R8.jar: core-renderer-R8.jar下载地址:http://cen ...
- Qualcomm platform, the commonly used parameters of charger and battery in device tree file
Platform MSM8917 PM8937 PMI8940 Parameters 1 battery charging voltage : qcom,float-voltage-mv = < ...
- Linux内核【链表】整理笔记(2) 【转】
转自:http://blog.chinaunix.net/uid-23069658-id-4725279.html 关于链表我们更多时候是对其进行遍历的需求,上一篇博文里我们主要认识了一下和链表操作比 ...
- [session篇]看源码学习session(一)
假如你是使用过或学习过PHP,你一定觉得很简单.session只不过是$_SESSION就可以搞得,这还不简单只是对一个key-value就能工作了.我觉得可以大多数的phper都是这样的,这是语言本 ...
- HDU 6118 度度熊的交易计划 最大费用可行流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6118 题意:中文题 分析: 最小费用最大流,首先建立源点 s ,与超级汇点 t .因为生产一个商品需要 ...