【Codeforces Round #455 (Div. 2) B】Segments
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
处理出所有的线
其实就是区间。
总共有n*(n+1)/2个
然后按照左端点、右端点排序
每次取最左边的线。
多种可能就取右端点尽量小的线。
v[i]i是左端点,里面的东西是右端点。
每个v[i]都从大到小排。
则每次取v[i]的最末端就可以了。
->然后作为新的x
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int n;
vector <int> v[N+10];
int GetFirst(int temp){
for (int i = temp;i <= n;i++)
if (v[i].size()>0){
return i;
}
return -1;
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n;
for (int i = 0;i <= n;i++)
for (int j = 1;j <= n;j++){
int y = i+j;
if (y>n) break;
v[i].push_back(y);
}
for (int i = 0;i <= n;i++){
sort(v[i].begin(),v[i].end());
reverse(v[i].begin(),v[i].end());
}
int cnt = 0;
int x = GetFirst(0);
while (x!=-1){
cnt++;
int y = v[x].back();
v[x].pop_back();
x = GetFirst(y);
while (x!=-1){
y = v[x].back();
v[x].pop_back();
x = GetFirst(y);
}
x = GetFirst(0);
}
cout << cnt << endl;
return 0;
}
【Codeforces Round #455 (Div. 2) B】Segments的更多相关文章
- 【Codeforces Round #455 (Div. 2) A】Generate Login
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举两个串的前缀长度就好. 组出来. 排序. 取字典序最小的那个. [代码] #include <bits/stdc++.h& ...
- 【Codeforces Round #455 (Div. 2) C】 Python Indentation
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 一个for循环之后. 下一个写代码的地方一是从(x+1,y+1)开始的 然后如果写完了一个simple statement 下次就有 ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
- 【Codeforces Round #423 (Div. 2) A】Restaurant Tables
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- 79.express里面的app.configure作用
以下摘自 express 3.0 的 文档 app.configure([env], callback) Conditionally invoke callback when env matches ...
- POJ 3256 DFS水题
枚举点 每次都搜一遍 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...
- 手动新建hive编程环境(以hive-1.0.0和hive-1.2.1为例)
如下,是用maven构建项目,本篇博文重点不是这个.初学者(小白)变成小鸟后,建议开始用maven啦! Eclipse下Maven新建项目.自动打依赖jar包(包含普通项目和Web项目) HBase ...
- Codeforces 344C Rational Resistance
Description Mad scientist Mike is building a time machine in his spare time. To finish the work, he ...
- 自己写unicode转换ascii码,wchar*到char*
对于ascii码的char事实上就是unicode码wchar的首个字节码, 如wchar[20] = "qqqq"; 在内存中排码事实上是char的'q' '\0'这类.因此我们 ...
- Linux下Oracle的sqlplus中上下左右退格键无法使用
一.配置yum源并安装readline* 配置本地yum 1.挂载光盘 mount /dev/cdrom /mnt/media 2,新建本地yun源的配置文件 vi /etc/yum.repos.d/ ...
- RvmTranslator6.3 is released
RvmTranslator6.3 is released eryar@163.com RvmTranslator can translate the RVM file exported by AVEV ...
- es62
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Android图像处理之熔铸特效
代码: package com.color; import android.content.Context; import android.graphics.Bitmap; import androi ...
- 42.管道,cmd执行指令写到管道中
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <stri ...