Knight Tournament
Codeforces Round #207 (Div. 1) A:http://codeforces.com/problemset/problem/356/A
题意:给你n匹马,然后有m场比赛。每场比赛有一个l,r,x,表示编号从l,r之间的马都被x给打败了,但是这里如果之前已经败了,那么这里的区间就不会包括了。
题解:题解,直接用一个set搞定。
思维过程:首先,想到,对于一场比赛来说,如果之前已经败了的话,这里就不用在考虑了,但是如何判断这个区间里面的马已经败了,朴素的想法,就是查询还是在这个区间,但是我把之前的已经败的马打上表示,然后再在这个区间内逐个进行判断,这样判断的话,区间内的每个元素都会被判断一次,可想而知,这样的想法是不对。时间复杂度hold不住。如何对于那些已经败的马不用判断。这里,可以用一个set来搞,把所有的元素放进set,当要删除一个区间的时候,只要用lower_bound找到第一个不小于l的数,然后往后找,直到到达右端点。然后把找到的点,从set中删除即可。这样,每次查询只在没有删除的马中进行,所以减少了许多不必要的判断。现在考虑复杂度。每个数,会被放进set和从set中删除一次,所以复杂度是n(logn).一定要利用题目中的各种信息,然后利用好自己的思维信息,寻找突破口,一点一滴的,总会有解决的方法。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
const int N=3e5+;
int ans[N],temp[N],top;
int n,m,l,r,x;
int main(){
while(~scanf("%d%d",&n,&m)){
set<int>Q;
for(int i=;i<=n;i++){
Q.insert(i);
}
for(int i=;i<=m;i++){
scanf("%d%d%d",&l,&r,&x);
top=;
set<int>::iterator it=Q.lower_bound(l);
for(;it!=Q.end();it++){
if((*it)>r)break;
if((*it)==x){
ans[x]=x;
}
else{
ans[(*it)]=x;
temp[++top]=(*it);
}
}
for(int i=;i<=top;i++){
Q.erase(temp[i]);
}
top=;
}
for(int i=;i<n;i++){
if(ans[i]==i)printf("0 ");
else
printf("%d ",ans[i]);
}
if(ans[n]==n)printf("0\n");
else
printf("%d\n",ans[n]);
} }
Knight Tournament的更多相关文章
- CodeForce 356A Knight Tournament(set应用)
Knight Tournament time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Knight Tournament 合并区间
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the me ...
- Knight Tournament (set)
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the me ...
- CodeForces - 357C Knight Tournament 伪并查集(区间合并)
Knight Tournament Hooray! Berl II, the king of Berland is making a knight tournament. The king has a ...
- D - Knight Tournament(set)
Problem description Hooray! Berl II, the king of Berland is making a knight tournament. The king has ...
- codeforces 357C Knight Tournament(set)
Description Hooray! Berl II, the king of Berland is making a knight tournament. The king has already ...
- Codeforces Round #207 (Div. 1) A. Knight Tournament(STL)
脑子又卡了...来一发set的,STL真心不熟. #include <stdio.h> #include <string.h> #include <iostream> ...
- cf C. Knight Tournament
http://codeforces.com/contest/357/problem/C #include <cstdio> #include <cstring> #includ ...
- Codeforces Round #207 (Div. 1) A. Knight Tournament (线段树离线)
题目:http://codeforces.com/problemset/problem/356/A 题意:首先给你n,m,代表有n个人还有m次描述,下面m行,每行l,r,x,代表l到r这个区间都被x所 ...
随机推荐
- leetcode-WordLadder
Word Ladder Total Accepted: 10243 Total Submissions: 58160My Submissions Given two words (start and ...
- docker 镜像中包含数据库环境和运行环境
需求: 一个镜像中要包含数据库环境和运行环境 Apache 环境 + mariadb 已经在拉取了Apache的运行环境 - 拉取代码 git https://github.com/timhaak/d ...
- 10.13 noip模拟试题
Porble 1时间与空间之旅(tstrip.*) 题目描述 公元22××年,宇宙中最普遍的交通工具是spaceship.spaceship的出现使得星系之间的联系变得更为紧密,所以spaceship ...
- sql 减去分钟
SQL SERVER:SELECT DATEADD( minute,-10,GETDATE()) ORACLE:SELECT to_char(sysdate -interval '10' minute ...
- CSS3 变形小结
为原始大小 b:纵向扭曲,0为不变 c :横向扭曲,0不变 d:垂直伸缩量,1为原始大小 e:水平偏移量,0为初始位置 f :垂直偏移向,0是初始位置 Ø原点 transform-origin() ...
- wsdlLocation可以写成项目的相对路劲吗
如果客户端的代码使用wsdl生成的话,这个地址是从wsdl描述的<service>里的<location>获取的,如果开发过程中服务地址换了,那只能手工来修改了,好像只有一个地 ...
- Spring通过SchedulerFactoryBean实现调度任务的配置
http://blog.csdn.net/hu_shengyang/article/details/19815201(里面是配置) 介绍SchedulerFactoryBean http://blog ...
- Core Data 教学
看了一篇国外的文章,关于iOS9的Core Data教学,在这里做了一下总结 Core Data 教学 示例开源地址:LastDayCoreData 在这篇文章中我们将学习Core Data的系列教程 ...
- 层模型--绝对定位(position:absolute)
如果想为元素设置层模型中的绝对定位,需要设置position:absolute(表示绝对定位),这条语句的作用将元素从文档流中拖出来,然后使用left.right.top.bottom属性相对于其最接 ...
- 添加Appicon的方法
1.将设计好的图片,拖拽到Groups&Files的Resources目录下: 2.修改Resources目录下的“工程名-info.plist”文件 3.修改该文件的Iconfile属性,填 ...