usaco-milk2-pass

呵呵,通过:

/*
ID: qq104801
LANG: C++
TASK: milk2
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* for debug only:counter
*/
void debug_dummy(void)
{
    return;
}

typedef struct _kk
{
    int a;
    int b;
}kk,*pkk;
kk k[5050];
int n;
int max1,max2;

int cmp(const void *a,const void *b)
{
    kk *p=(kk*)a,*q=(kk*)b;
    if (p->a!=q->a) return p->a - q->a;
    return p->b - q->b;
}

void milk()
{
    int m,end,i;
    max2=0;
    max1=m=k[0].b-k[0].a;
    end=k[0].b;
    for (i=1;i<n;i++)
    {
        if(k[i].a>end)
        {
            if((k[i].a-end)>max2)
            {
                max2=k[i].a-end;
            }
            m=k[i].b-k[i].a;            

        }
        if(k[i].a<=end && k[i].b>end)
        {
            m+=k[i].b-end;
        }
        if(m>max1)
            max1=m;

        if(k[i].b>end)
            end=k[i].b;
    }
}

main () {
    FILE *fin = fopen ("milk2.in", "r");
    FILE *fout = fopen ("milk2.out", "w");
    fscanf(fin,"%d",&n);
    int i;
    for(i=0;i<n;i++)
    {
        fscanf(fin,"%d %d",&k[i].a,&k[i].b);
        //printf("%d %d\n",k[i].a,k[i].b);
    }
    //printf("\n");
    qsort(k,n,sizeof(kk),cmp);
    for(i=0;i<n;i++)
    {
        //printf("%d %d\n",k[i].a,k[i].b);
    }  

    milk();
    //printf("max1:%d max2:%d\n",max1,max2);

    fprintf(fout,"%d %d\n",max1,max2);
    fclose(fin);
    fclose(fout);
    exit (0);
}

呵呵,测试数据:

USER: ll tom [qq104801]
TASK: milk2
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.003 secs, 3532 KB]
   Test 2: TEST OK [0.008 secs, 3532 KB]
   Test 3: TEST OK [0.008 secs, 3532 KB]
   Test 4: TEST OK [0.003 secs, 3532 KB]
   Test 5: TEST OK [0.003 secs, 3532 KB]
   Test 6: TEST OK [0.005 secs, 3532 KB]
   Test 7: TEST OK [0.014 secs, 3532 KB]
   Test 8: TEST OK [0.024 secs, 3532 KB]

All tests OK.

Your program (‘milk2‘) produced all correct answers! This is your submission #5 for this problem. Congratulations!

Here are the test data inputs:

------- test 1 ----
1
100 200
------- test 2 ----
4
100 200
201 301
302 402
403 503
------- test 3 ----
10
2 3
4 5
6 7
8 9
10 11
12 13
14 15
16 17
18 19
1 20
------- test 4 ----
3
100 102
64100 64102
128100 128102
------- test 5 ----
100
99000 101000
98000 102000
97000 103000
96000 104000
95000 105000
94000 106000
93000 107000
92000 108000
91000 109000
90000 110000
89000 111000
88000 112000
87000 113000
86000 114000
85000 115000
84000 116000
83000 117000
82000 118000
81000 119000
80000 120000
79000 121000
78000 122000
77000 123000
76000 124000
75000 125000
74000 126000
73000 127000
72000 128000
71000 129000
70000 130000
69000 131000
68000 132000
67000 133000
66000 134000
65000 135000
64000 136000
63000 137000
62000 138000
61000 139000
60000 140000
59000 141000
58000 142000
57000 143000
56000 144000
55000 145000
54000 146000
53000 147000
52000 148000
51000 149000
50000 150000
49000 151000
48000 152000
47000 153000
46000 154000
45000 155000
44000 156000
43000 157000
42000 158000
41000 159000
40000 160000
39000 161000
38000 162000
37000 163000
36000 164000
35000 165000
34000 166000
33000 167000
32000 168000
31000 169000
30000 170000
29000 171000
28000 172000
27000 173000
26000 174000
25000 175000
24000 176000
23000 177000
22000 178000
21000 179000
20000 180000
19000 181000
18000 182000
17000 183000
16000 184000
15000 185000
14000 186000
13000 187000
12000 188000
11000 189000
10000 190000
9000 191000
8000 192000
7000 193000
6000 194000
5000 195000
4000 196000
3000 197000
2000 198000
1000 199000
0 200000
------- test 6 ----
6
100 200
200 400
400 800
800 1600
50 100
1700 3200
------- test 7 ----
1000
26022 26065
17435 17463
17766 17811
6543 6575
19436 19516
17161 17174
11704 11736
11040 11088
8106 8142
19810 19855
9464 9473
13056 13082
20364 20421
19954 19959
2697 2765
3465 3548
9267 9282
26107 26138
20459 20550
14267 14358
14968 15068
12099 12156
21594 21616
7965 8023
11094 11171
453 480
15105 15113
26944 27006
11120 11126
21755 21819
24531 24628
26838 26900
18740 18760
14038 14044
24321 24322
1917 1971
14251 14321
14145 14146
8207 8225
18448 18454
8917 8949
1116 1180
29584 29606
28081 28127
7356 7428
31553 31555
21880 21893
5218 5231
5903 5983
27001 27100
6937 6962
24391 24466
26994 27055
13325 13381
19376 19381
21636 21639
29536 29630
12074 12081
2985 3033
7868 7884
15284 15331。。。。。。
时间: 2024-08-08 21:18:59

usaco-milk2-pass的相关文章

USACO Milk2 区间合并

这题WA了四次,后来发现不能用所谓的桶排来写 虽然空间上是可以的,但是存在这样一个问题 比如两组数据[15,20]和[21,30] 在20 和 21这两个时刻之间没有milking,但是用桶排的方法写的话只能判断离散的量 不能判断连续的量. 所以这题应该要用[区间合并]的思想来写 不错的题目~ Souce code: /* ID: wushuai2 PROG: milk2 LANG: C++ */ //#pragma comment(linker, "/STACK:16777216")

【USACO1.2.1】Milking Cows

Milking Cows Three farmers rise at 5 am each morning and head for the barn to milk three cows. The first farmer begins milking his cow at time 300 (measured in seconds after 5 am) and ends at time 1000. The second farmer begins at time 700 and ends a

USACO SECTION1 2.1 Milking Cows 简单贪心

题目链接: http://train.usaco.org/usacoprob2?a=p8taXWtZBpU&S=milk2 题目描述: 给出n组数, 求出最长连续有数区间与最长连续无数区间 解题思路: 简单贪心, 先排序, 然后如果有交集判断右端点,如果右端点大则延伸, 否则continue, 如果无交集更新两个ans. 代码: http://train.usaco.org/usacoprob2?a=p8taXWtZBpU&S=milk2 思考: 简单的贪心我的代码却WA了, 记住一切从简

【USACO 1.2.1】挤牛奶

[问题描述] 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶.第一个农民在300时刻(从5点开始计时,秒为单位)给他的牛挤奶,一直到1000时刻.第二个农民在700时刻开始,在 1200时刻结束.第三个农民在1500时刻开始2100时刻结束.期间最长的至少有一个农民在挤奶的连续时间为900秒(从300时刻到1200时刻),而最长的无人挤奶的连续时间(从挤奶开始一直到挤奶结束)为300时刻(从1200时刻到1500时刻). 你的任务是编一个程序,读入一个有N个农民(1 <= N <= 5000

Usaco Open09 Gold

Problem 1: Ski Lessons [Brian Jacokes, 2002] Farmer John wants to take Bessie skiing in Colorado. Sadly, Bessie is not really a very good skier. Bessie has learned that the ski resort is offering S (0 <= S <= 100) ski classes throughout the day. Les

COGS 696. [IOI1996][USACO 2.3] 最长前缀

★   输入文件:prefix.in   输出文件:prefix.out   简单对比时间限制:1 s   内存限制:128 MB 描述 USACO 2.3.1 IOI96 在生物学中,一些生物的结构是用包含其要素的大写字母序列来表示的.生物学家对于把长的序列分解成较短的序列(即元素)很感兴趣. 如果一个集合 P 中的元素可以通过串联(元素可以重复使用,相当于 Pascal 中的 “+” 运算符)组成一个序列 S ,那么我们认为序列 S 可以分解为 P 中的元素.元素不一定要全部出现(如下例中B

USACO prefix TrieTree + DP

/* ID:kevin_s1 PROG:prefix LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <cstdlib>

【USACO 1.3.4】牛式

[題目描述 ] 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ---------- * * * * * * ---------- * * * * 数字只能取代*,当然第一位不能为0,况且给定的数字里不包括0. 注意一下在美国的学校中教的"部分乘积",第一部分乘积是第二个数的个位和第一个数的积,第二部分乘积是第二个数的十位和第一个数的乘积. 写一个程序找出所有的牛式. [格式] INPUT FORMAT: (f

USACO Chapter 1 Section 1.1

USACO的题解和翻译已经很多了... 我只是把自己刷的代码保存一下. 1.PROB Your Ride Is Here 1 /* 2 ID:xiekeyi1 3 PROG:ride 4 LANG:C++ 5 */ 6 7 #include<bits/stdc++.h> 8 using namespace std ; 9 10 int main() 11 { 12 freopen("ride.in","r",stdin); 13 freopen(&quo

pass语句

Python pass是空语句,是为了保持程序结构的完整性.  pass 不做任何事情,一般用做占位语句. #!/usr/bin/python # -*- coding: UTF-8 -*- # 输出 Python 的每个字母 for letter in 'Python': if letter == 'h': pass print '这是 pass 块' print '当前字母 :', letter print "Good bye!" 执行结果: 当前字母 : P 当前字母 : y 当