| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 639 人关注过本帖
标题:[讨论]做了好几天没过的一个题目,班主||高手进
取消只看楼主 加入收藏
zgwxwn
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-4-24
收藏
 问题点数:0 回复次数:2 
[讨论]做了好几天没过的一个题目,班主||高手进

Cleaning Shifts
Time Limit:1000MS Memory Limit:65536K
Total Submit:108 Accepted:32

Description
Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most obliging of farmers, has no choice but hire some of the cows to clean the barn.

Farmer John has N (1 <= N <= 10,000) cows who are willing to do some cleaning. Because dust falls continuously, the cows require that the farm be continuously cleaned during the workday, which runs from second number M to second number E during the day (0 <= M <= E <= 86,399). Note that the total number of seconds during which cleaning is to take place is E-M+1. During any given second M..E, at least one cow must be cleaning.

Each cow has submitted a job application indicating her willingness to work during a certain interval T1..T2 (where M <= T1 <= T2 <= E) for a certain salary of S (where 0 <= S <= 500,000). Note that a cow who indicated the interval 10..20 would work for 11 seconds, not 10. Farmer John must either accept or reject each individual application; he may NOT ask a cow to work only a fraction of the time it indicated and receive a corresponding fraction of the salary.

Find a schedule in which every second of the workday is covered by at least one cow and which minimizes the total salary that goes to the cows.

Input
Line 1: Three space-separated integers: N, M, and E.

Lines 2..N+1: Line i+1 describes cow i's schedule with three space-separated integers: T1, T2, and S.

Output
Line 1: a single integer that is either the minimum total salary to get the barn cleaned or else -1 if it is impossible to clean the barn.

Sample Input


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

Sample Output


5

Hint
Explanation of the sample:

FJ has three cows, and the barn needs to be cleaned from second 0 to second 4. The first cow is willing to work during seconds 0, 1, and 2 for a total salary of 3, etc.

Farmer John can hire the first two cows.

Source
USACO 2005 December Silver

搜索更多相关主题的帖子: 班主 Farmer cows 
2007-03-05 03:16
zgwxwn
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-4-24
收藏
得分:0 

我用bfs做了一下 超时了
# include <stdio.h>
# include <stdlib.h>
# define MaxVNum 100000

int N;
static long min = 2000000000;
long M, E;

typedef int VertexType;
typedef struct node
{
int adjvex;
struct node *next;
int weight;
}EdgeNode;
typedef struct vnode
{
EdgeNode *firstedge;
}VertexNode;
typedef VertexNode AdjList[MaxVNum];
typedef struct ALGraph
{
AdjList adjlist;
int n;
}Graphic;

void CreateGraph(Graphic *G)
{
int i;
EdgeNode *s;
long t1, t2, w;

scanf("%d%ld%ld\n",&N,&M,&E);
G->n = E-M+1;
for(i = 0; i < G->n; i++)
G->adjlist[i].firstedge = NULL;
for(i = 0; i < N; i++)
{
scanf("%ld%ld%ld",&t1,&t2,&w);
s = (EdgeNode *)malloc(sizeof(EdgeNode));
s->adjvex = t2-M;
s->weight = w;
s->next = G->adjlist[t1-M].firstedge;
G->adjlist[t1-M].firstedge = s;
}
}
void dfs(Graphic *G,int prev,int v,long S)
{
int mark;
EdgeNode *s;

if(S>=min)
return ;
mark = 1;
s = G->adjlist[v].firstedge;
if(v==G->n)
mark = 0;
if(v<=G->n-1&&s == NULL)
{
//printf("Y\n");

while(--v > prev)
{
// printf("%d %d\n",prev,v);
// system("pause");
s = G->adjlist[v].firstedge;
if(s != NULL)
dfs(G,1,v,S);
}
mark = 0;
}
while(mark&&s)
{
// printf("!%d %d %ld\n",v,s->adjvex+1,S);
// system("pause");
dfs(G,v,s->adjvex+1,s->weight+S);
s = s->next;
}
if(v==G->n)
if(S < min)
{
min = S;
//printf("MIN\n");
}
}
int main()
{
Graphic G;

CreateGraph(&G);
dfs(&G,0,0,0);
if(min == 2000000000)
printf("-1\n");
else
printf("%ld\n",min);
return 1;
}


coding & enjoying
2007-03-05 03:18
zgwxwn
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-4-24
收藏
得分:0 

过了 用dijkstra

[此贴子已经被作者于2007-3-6 22:15:05编辑过]


coding & enjoying
2007-03-06 22:14
快速回复:[讨论]做了好几天没过的一个题目,班主||高手进
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046395 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved