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恤,垮裤,运动鞋)或白领风格( ...
随机推荐
- Vue前端开发规范(山东数漫江湖)
一.强制 1. 组件名为多个单词 组件名应该始终是多个单词的,根组件 App 除外. 正例: export default { name: 'TodoItem', // ... } 反例: expor ...
- TOYS(计算几何基础+点与直线的位置关系)
题目链接:http://poj.org/problem?id=2318 题面: TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submiss ...
- python初步学习-python数据类型-列表(list)
列表 list 在 python 中具有非常强大的功能 定义 在python中,用方括号表示一个list:[] 在方括号里面,可以是 int,也可以是 str类型的数据,甚至也可以是Flase/Tru ...
- js获取屏幕高度宽度
获取各种屏幕的宽度和高度Javascript: 网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽 ...
- 2.0 docker安装
问题列表: Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again 解:处 ...
- 数据库===轻量级mysql数据库管理工具
已经上传至: https://download.csdn.net/download/bo_mask/10276952
- jython
# -*- coding: utf-8 -*- import sys import json sys.path += ["C:/Users/yangbo/Desktop/restassure ...
- perl多线程tcp端口扫描器(原创)
perl多线程tcp端口扫描器(原创) http://bbs.chinaunix.net/thread-1457744-1-1.html perl socket 客户端发送消息 http://blog ...
- mongodb 学习笔记--- 基础知识
1.mongodb的安装 (1) mac使用brew 安装就好 brew install mongodb (2) mkdir /data/db 作为mongodb默认的数据目录 并 sudo chow ...
- binlog2sql 回滚误操作
参考过在资料: https://github.com/wuyongshenghub/mysqlbinlog2sql https://www.cnblogs.com/xuanzhi201111/p/66 ...