POJ 3829 Seat taking up is tough(——只是题目很长的模拟)
题目链接:
http://poj.org/problem?id=3829
题意描述:
输入矩阵的大小n和m,以及来占位置的人数k
输入n*m的教室座位矩阵,每个值表示该座位的满意度
输入每个人来占位置的时间和需要几个位置h,m,q
计算并输出每个来占位置的人根据占位规则得到的坐标zx,zy,若一个位置都没有了,输出-1。
规则:
首先看有没有在同一行上的连续的k个座位,有则这个占位的同学坐在这连续k个座位的最左边,如果有多行上都存在连续的k个位置,则该占位的同学会选择最左边值最大的位置(坑点就在这,不是k个位置
的和最大),如果不存在在同一行上的连续的k个位置,则只需在现有的空位上挑一个满意度最大的给自己坐就行了,如果一个位置都没有了,就输出-1。
另外题目需要按照提问的顺序给出答案,也就是说给的时间可能使乱序的,但是最后输出结果的时候要按照提问顺序输出答案。
AC代码:
#include<stdio.h>
#include<algorithm>
using namespace std;
int inf=;
int a[][];
struct T
{
int z,h,m,q,zx,zy,f; //z表示提问顺序,最后按该值排序
}; //f表示该占位同学能否找到一个位置
struct T t[];
int cmp(struct T a,struct T b)
{ //先按照小时排,再按分钟排
if(a.h<b.h)
return ;
else if(a.h==b.h)
{
if(a.m<b.m)
return ;
else
return ;
}
return ;
}
int cmp1(struct T a,struct T b)
{
return a.z<b.z;
}
int main()
{
int i,j,k,l,m,n,b[],qq;
long long max;
while(scanf("%d%d%d",&n,&m,&qq), n+m+qq != )
{
for(i=;i<=n;i++)
for(j=;j<=m;j++)
scanf("%d",&a[i][j]);
for(j=;j<=n;j++) //表示该行还有几个座位
b[j]=m;
for(i=;i<=qq;i++)
{
t[i].f=;
t[i].z=i;
scanf("%d:%d%d",&t[i].h,&t[i].m,&t[i].q);
}
sort(t+,t+qq+,cmp);
/*for(i=1;i<=qq;i++)
printf("%d %d %d\n",t[i].h,t[i].m,t[i].q);*/
for(l=;l<=qq;l++)
{
max=-inf;
int x;int y;
long long sum;
int s=;
for(i=;i<=n;i++)
if(b[i]==) s++;
if(s==n)
{
t[l].f=;
continue;
}
for(i=;i<=n;i++)
{
sum=;
if(b[i]>=t[l].q)
{
for(j=;j<=m-t[l].q+;j++)
{
sum=a[i][j];
for(k=j;k<j+t[l].q;k++)
if(a[i][k]==-inf) break;
if(k==j+t[l].q&&max<sum)
{
max=sum;
x=i;y=j;
}
}
}
}
if(max==-inf)
{
int mx1=-inf;
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
if(mx1<a[i][j])
{
mx1=a[i][j];
x=i;y=j;
}
}
}
b[x]--;
a[x][y]=-inf;
}
else
{
b[x]-=t[l].q;
for(j=y;j<y+t[l].q;j++)
a[x][j]=-inf;
}
t[l].f=;
t[l].zx=x;
t[l].zy=y;
}
sort(t+,t+qq+,cmp1);
for(i=;i<=qq;i++)
{
if(t[i].f)
printf("%d %d\n",t[i].zx,t[i].zy);
else
printf("-1\n");
}
}
return ;
}
POJ 3829 Seat taking up is tough(——只是题目很长的模拟)的更多相关文章
- HDU 3262/POJ 3829 Seat taking up is tough(模拟+搜索)(2009 Asia Ningbo Regional)
Description Students often have problems taking up seats. When two students want the same seat, a qu ...
- hdu 3262 09 宁波 现场 C - Seat taking up is tough 暴力 难度:0
Description Students often have problems taking up seats. When two students want the same seat, a qu ...
- HDU 3262 Seat taking up is tough (模拟搜索)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3262 题意:教室有n*m个座位,每个座位有一个舒适值,有K个学生在不同时间段进来,要占t个座位,必须是连 ...
- POJ 1743 Musical Theme (后缀数组,求最长不重叠重复子串)(转)
永恒的大牛,kuangbin,膜拜一下,Orz 链接:http://www.cnblogs.com/kuangbin/archive/2013/04/23/3039313.html Musical T ...
- POJ 3261 Milk Patterns 可重复k次的最长重复子串
Milk PatternsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3261 Description ...
- poj 1743 男人八题之后缀数组求最长不可重叠最长重复子串
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14874 Accepted: 5118 De ...
- POJ 3654 & ZOJ 2936 & HDU 2723 Electronic Document Security(模拟)
题目链接: PKU:http://poj.org/problem?id=3654 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
- POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】
Frogger Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- Poj 1743——Musical Theme——————【后缀数组,求最长不重叠重复子串长度】
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22499 Accepted: 7679 De ...
随机推荐
- zepto的返回顶部scrollTop的动画解决方法
写移动端的时候,引入的zepto.js里的animate不包括scrollTop,所以返回顶部的时候,没有动画的效果.这里我使用的是setInterval的方法.代码详情如下 <!DOCTYPE ...
- node基础篇二:模块、路由、全局变量课堂(持续)
今天继续更新node基础篇,今天主要内容是模块.路由和全局变量. 模块这个概念,在很多语言中都有,现在模块开发已经成为了一种潮流,它能够帮助我们节省很多的时间,当然咱们的node自然也不能缺少,看下例 ...
- 10 Easy Steps to a Complete Understanding of SQL
原文出处:http://tech.pro/tutorial/1555/10-easy-steps-to-a-complete-understanding-of-sql(已经失效,现在收集如下) Too ...
- UWP 使用OneDrive云存储2.x api(二)【全网首发】
接上一篇 http://www.cnblogs.com/hupo376787/p/8032146.html 上一篇提到为了给用户打造一个完全无缝衔接的最佳体验,UWP开发者最好也要实现App设置和数据 ...
- FPGA 设计总结(1)
1. set_input_delay和set_output_delay的选项-max和-min的理解 首先 input/output其实是模拟数据在端口外的延时,是一个外部约束条件,目的是为了约束FP ...
- 解决 axios 返回空对象的问题
问题描述:
- python3基础(二)
loops循环语句 一 if语句,if语句配合else使用,可以没有else. 单分支if语句 age = input('Age:') password = '67' if age == passwo ...
- Nexus私服忘记用户名密码解决4步走
1 停止nexus服务 [root@node001 bin]# /usr/local/nexus/nexus-2.14.5-02/bin/nexus stop******************** ...
- InnoDB锁机制
1. 锁类型 锁是数据库区别与文件系统的一个关键特性,锁机制用于管理对共享资源的并发访问. InnoDB使用的锁类型,分别有: 共享锁(S)和排他锁(X) 意向锁(IS和IX) 自增长锁(AUTO-I ...
- 推荐一个比HtmlWebpackPlugin更灵活的插件
插件:html-res-webpack-plugin https://github.com/lcxfs1991/html-res-webpack-plugin/blob/v3/README_ZH.md ...