注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

东月之神

在单纯的观念里面,生命就容易变得比较深刻!

 
 
 

日志

 
 
关于我

别驻足,梦想要不停追逐,别认输,熬过黑暗才有日出,要记住,成功就在下一步,路很苦,汗水是最美的书!

网易考拉推荐
GACHA精选

zju 3317 Murder in Restaurant  

2010-04-10 21:37:20|  分类: ACM |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Time Limit: 1 Second      Memory Limit: 32768 KB

Murder in closet happened again in a small restaurant and Conan went there to collect evidence with Kogoro. After they reached the restaurant, they got a list of renters that lived in this restaurant recently. Yet the list was so long that they couldn't get the useful information from it. As an assistant of Conan, you must have been ready to help him to get the information on which rooms the renters have lived in.

Input

There are no more than 20 test cases. The first line of each test case contains two integers n and m, indicating the number of renters and the rooms of the restaurant (0 < n, m <= 100). The i-th line of the next n lines contains two integers t1 and t2, the day when they wanted to check in and to leave (0 < t1 < t2 <= 1000).

Each renter rends exactly one room and their check-in days are distinct. Each time a renter came, the owner would give him/her an available room with minimum room number if there were still empty rooms. Otherwise the renter would leave at once and never come back again. Note that rooms are always returned in morning and rented in afternoon. The input is ended with two zeroes.

Output

For each test case, output n lines of integers. The i-th integer indicates the room number of the i-th renter. The rooms are numbered from 1. If someone didn't live in this restaurant, output 0 in the corresponding line.

Sample Input

2 5
1 3
2 4
4 2
1 5
2 3
3 5
4 5
0 0

Sample Output

1
2
1
2
2
0

被这水题搞了好长的时间。拿来发泄一下、、、

#include <cstring>
#include <iostream>
using namespace std;

struct node
{
 int t1, t2, num, ans;
}s[101], temp;

bool hash[101];
bool a[101];

int main()
{
 int n, m, i, j, k;
 while(scanf("%d%d", &n, &m) != EOF)
 {
  if(n == 0 && m == 0) break;
  memset(s, 0, sizeof(s));
  memset(a, 0, sizeof(a));
  for(i = 0; i < n; i++)
  {
   cin >> s[i].t1 >> s[i].t2;
   s[i].num = i;
  }
  for(i = 0; i < n - 1; i++)
  {
   for(j = i + 1; j < n; j++)
   {
    if(s[i].t1 > s[j].t1)
    {
     temp = s[i];
     s[i] = s[j];
     s[j] = temp;
    }
   }
  }  
  memset(hash, 0, sizeof(hash));
  for(i = 0; i < n; i++)
  {
   for(k = 0; k < i; k++)
   {
    if(hash[k]) continue;
    if(s[i].t1 >= s[k].t2)
     {
      a[s[k].ans] = 0;
      hash[k] = 1;
     }
   }
   for(k = 1; k <= m; k++)
    if(!a[k])
     break;
   if(k == m + 1) 
    hash[i] = 1;
   else
   { 
    s[i].ans = k;
    a[k] = 1;
   }
  }
  for(i = 0; i < n - 1; i++)
  {
   for(j = i + 1; j < n; j++)
   {
    if(s[i].num > s[j].num)
    {
     temp = s[i];
     s[i] = s[j];
     s[j] = temp;
    }
   }
  }
  for(i = 0; i < n; i++)
   printf("%d\n", s[i].ans);
 }
return 0;
}

  评论这张
 
阅读(233)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017