CCF-老师拿钥匙20170902
来源:互联网 发布:程序员高级证书如何考 编辑:程序博客网 时间:2024/04/29 13:35
#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;
}
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] = n;
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] = 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[n] == -1) {
result[n] = act.room;
break;
}
}
}
else { // get 取
for(int n=1; n<=N; n++) {
if(result[n] == act.room) {
result[n] = -1;
break;
}
}
}
}
/***********************结果输出**********************************/
for(int n=1; n<=N; n++) {
cout<<result[n]<<" ";
}
}
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[n] == -1) {
result[n] = act.room;
break;
}
}
}
else { // get 取
for(int n=1; n<=N; n++) {
if(result[n] == act.room) {
result[n] = -1;
break;
}
}
}
}
/***********************结果输出**********************************/
for(int n=1; n<=N; n++) {
cout<<result[n]<<" ";
}
}
阅读全文
0 0
- CCF-老师拿钥匙20170902
- 今天拿了钥匙。。。
- csp/ccf 钥匙问题
- ccf公共钥匙盒
- ccf/公共钥匙盒
- CCF 公共钥匙盒
- CCF 公共钥匙盒
- CCF-20170902-公共钥匙盒(30分)
- ccf 公共钥匙盒 模拟
- ccf csp 公共钥匙盒
- CCF之公共钥匙盒
- CCF 201709-02公共钥匙盒
- 201709-2 公共钥匙盒 ccf
- 【ccf 201709-2】公共钥匙盒
- CCF 201709-2 公共钥匙盒
- CCF 201709-2公共钥匙盒 Java
- 201709-2 公共钥匙盒 ccf
- CCF-201709-2-公共钥匙盒
- Java 代码测试接口的方法
- GitWeb学习笔记
- CUDA学习笔记(1):环境搭建
- Android 中内存泄漏的原因和解决方案
- 华为2016校园招聘上机笔试题:简单错误记录 [python]
- CCF-老师拿钥匙20170902
- spring整合Junit
- [BI基础] 一些不得不了解的概念
- <span>与<div>标签
- 部署在服务器上的应用请求json文件返回404解决方法及原因分析
- spring mvc配置 + dbcp数据源+jdbcTemplate
- Spring事务传播机制和隔离机制
- Activity全屏非全屏的切换
- 自制弹出框--公告消息