CCF-老师拿钥匙20170902
2017-11-14 14:17
162 查看
#include <bits/stdc++.h>
using namespace std;
/***********************class**********************************/
class Action {
public:
int room; //钥匙号
int time; //归还事件发生的时间
int type; // 0:还钥匙, 1:借钥匙
//构造函数(初始化列表)进行类的初始化
Action(int room_, int time_, int type_) : room(room_), time(time_), type(type_) {}
/********************重载operator<函数 *******************************/
bool operator<(const Action &other) const {
if(time<other.time) return true;
else if(time==other.time && type<other.type) return true;
else if(time==other.time && type==other.type && room<other.room) return true;
return false;
}
};
/*
********************重写operator<函数 *******************************
小于号时升序排序
int cmp(Action action1,Action action2)
{
if(action1.time < action2.time){
return 1;
}else if(action1.time == action2.time
&& action1.type < action2.type){
return 1;
}else if(action1.time == action2.time
&& action1.type == action2.type
&& action1.room < action2.room){
return 1;
}
return 0;
}
*/
int main() {
int N, K;
cin>>N>>K;
//创建Action类型的Vector数组
vector<Action> actions;
//钥匙的初始化排序
vector<int> result(N+1);
for(int n=1; n<=N; n++) result
= n;
for(int k=0; k<K; k++) {
int room, begin, length;
cin>>room>>begin>>length;
actions.push_back(Action(room, begin, 1));//借钥匙
actions.push_back(Action(room, begin+length, 0));
}
/*************sort利用operator<重写函数进行排序 *************************/
sort(actions.begin(), actions.end());
/***********************取放操作**********************************/
for(int i=0; i<actions.size(); i++) {
Action &act = actions[i];
if(act.type == 0) { // put放
for(int n=1; n<=N; n++) {
if(result
== -1) {
result
= act.room;
break;
}
}
}
else { // get 取
for(int n=1; n<=N; n++) {
if(result
== act.room) {
result
= -1;
break;
}
}
}
}
/***********************结果输出**********************************/
for(int n=1; n<=N; n++) {
cout<<result
<<" ";
}
}
using namespace std;
/***********************class**********************************/
class Action {
public:
int room; //钥匙号
int time; //归还事件发生的时间
int type; // 0:还钥匙, 1:借钥匙
//构造函数(初始化列表)进行类的初始化
Action(int room_, int time_, int type_) : room(room_), time(time_), type(type_) {}
/********************重载operator<函数 *******************************/
bool operator<(const Action &other) const {
if(time<other.time) return true;
else if(time==other.time && type<other.type) return true;
else if(time==other.time && type==other.type && room<other.room) return true;
return false;
}
};
/*
********************重写operator<函数 *******************************
小于号时升序排序
int cmp(Action action1,Action action2)
{
if(action1.time < action2.time){
return 1;
}else if(action1.time == action2.time
&& action1.type < action2.type){
return 1;
}else if(action1.time == action2.time
&& action1.type == action2.type
&& action1.room < action2.room){
return 1;
}
return 0;
}
*/
int main() {
int N, K;
cin>>N>>K;
//创建Action类型的Vector数组
vector<Action> actions;
//钥匙的初始化排序
vector<int> result(N+1);
for(int n=1; n<=N; n++) result
= n;
for(int k=0; k<K; k++) {
int room, begin, length;
cin>>room>>begin>>length;
actions.push_back(Action(room, begin, 1));//借钥匙
actions.push_back(Action(room, begin+length, 0));
}
/*************sort利用operator<重写函数进行排序 *************************/
sort(actions.begin(), actions.end());
/***********************取放操作**********************************/
for(int i=0; i<actions.size(); i++) {
Action &act = actions[i];
if(act.type == 0) { // put放
for(int n=1; n<=N; n++) {
if(result
== -1) {
result
= act.room;
break;
}
}
}
else { // get 取
for(int n=1; n<=N; n++) {
if(result
== act.room) {
result
= -1;
break;
}
}
}
}
/***********************结果输出**********************************/
for(int n=1; n<=N; n++) {
cout<<result
<<" ";
}
}
相关文章推荐
- CCF 201709-02公共钥匙盒
- [置顶] ccf-csp 2017-09-02 公共钥匙盒
- ccf公共钥匙盒
- CCF 公共钥匙盒
- CCF-CSP 公共钥匙盒
- CCF CSP 201709-2:公共钥匙盒
- CCF-20170902-公共钥匙盒(30分)
- ccf_201709-2 公共钥匙盒
- 离散事件模拟:公共钥匙盒问题(2017年9月CCF第二题)
- CCF CSP 201709-2 公共钥匙盒
- CCF CSP 201709-2 公共钥匙盒
- CCF-201709-2-公共钥匙盒
- ccf-csp - 2017-09-02 公共钥匙盒
- CCF CSP试题题解:201709-2 公共钥匙盒
- ccf csp 公共钥匙盒
- CCF 公共钥匙盒
- [CCFwithAxin]201709-2公共钥匙盒
- 郭汉尧老师之奇安达营销团队提升特训
- 移动互联风口频现,百度高德谁已手握地图关键钥匙
- 新东方老师的博客上找来的