A research group is developing a computer program that will fetch historical stock market quotes from a service that charges a fixed fee for each day's quotes that it delivers. The group has examined the collection of previously-requested quotes and discovered a lot of duplication, resulting in wasted money. So the new program will maintain a list of all past quotes requested by members of the group. When additional quotes are required, only quotes for those dates not previously obtained will be fetched from the service, thus minimizing the cost.

You are to write a program that d etermines when new quotes are required. Input for the program consists of the date ranges for which quotes have been requested in the past and the date ranges for which quotes are required. The program will then determine the date ranges for which quotes must be fetched from the service.

Input

There will be multiple input cases. The input for each case begins with two non-negative integers  NX  and  NR , (   0NXNR100 ).  NX  is the number of existing date ranges for quotes requested in the past.  NR  is the number of date ranges in the incoming requests for quotes. Following these are  NX + NR  pairs of dates. The first date in each pair will be less than or equal to the second date in the pair. The first  NX  pairs specify the date ranges of quotes which have been requested and obtained in the past, and the next  NR  pairs specify the date ranges for which quotes are required.

Two zeroes will follow the input data for the last case.

Each input date will be given in the form YYYYMMDDYYYY is the year (1700 to 2100), MM is the month (01 to 12), and DD is the day (in the allowed range for the given month and year). Recall that months 04, 06, 09, and 11 have 30 days, months 01, 03, 05, 07, 08, 10, and 12 have 31 days, and month 02 has 28 days except in leap years, when it has 29 days. A year is a leap year if it is evenly divisible by 4 and is not a century year (a multiple of 100), or if it is divisible by 400.

Output

For each input case, display the case number (1, 2, ...) followed by a list of any date ranges for which quotes must be fetched from the service, one date range per output line. Use the American date format shown in the sample output below. Explicitly indicate (as shown) if no additional quotes must be fetched. If two date ranges are contiguous or overlap, then merge them into a single date range. If a date range consists of a single date, print it as a single date, not as a range consisting of two identical dates. Display the date ranges in chronological order, starting with the earliest date range.

Sample Input

1 1
19900101 19901231
19901201 20000131
0 3
19720101 19720131
19720201 19720228
19720301 19720301
1 1
20010101 20011231
20010515 20010901
0 0

Sample Output

Case 1:
1/1/1991 to 1/31/2000 Case 2:
1/1/1972 to 2/28/1972
3/1/1972 Case 3:
No additional quotes are required.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int n,m,i,j,a,b,cases,no_quotes,st[101],ed[101];
int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char c[147000];
int leap(int y)
{
return y%400==0||y%4==0&&y%100;
} void get_date(int day)
{
int y,m;
for(y=1700;day>365+leap(y);y++)
day-=365+leap(y);
for(m=1;day>days[m]+(m==2&&leap(y));m++)
day-=days[m]+(m==2&&leap(y));
printf("%d/%d/%d",m,day,y);
} int f(int x)
{
int i,tmp,sum;
tmp=x/10000;
sum=0;
for(i=1700;i<tmp;i++)
{
sum+=365;
if(leap(i))
sum++;
}
tmp=x%10000/100;
for(i=1;i<tmp;i++)
{
sum+=days[i];
if(i==2&&leap(x/10000))
sum++;
}
return sum+x%100;
} void fill(int a,int b,int x)
{
int fa,fb;
fa=f(a);
fb=f(b);
memset(&c[fa],x,fb-fa+1);
} int main()
{
while(scanf("%d%d",&n,&m)&&n+m)
{
if(cases)
printf("\n");
memset(c,0,sizeof(c));
for(i=0;i<n;i++)
scanf("%d%d",&st[i],&ed[i]);
for(i=0;i<m;i++)
{
scanf("%d%d",&a,&b);
fill(a,b,2);
}
for(i=0;i<n;i++)
fill(st[i],ed[i],1);
printf("Case %d:\n",++cases);
no_quotes=1;
for(i=0;i<147000;i++)
if(c[i]>1)
{
no_quotes=0;
printf(" ");
get_date(i);
if(c[i+1]<2)
printf("\n");
else
{
printf(" to ");
for(j=i;c[j]>1;j++);
get_date(j-1);
printf("\n");
i=j;
}
}
if(no_quotes)
printf(" No additional quotes are required.\n");
}
return 0;
}


												

1032 - Intersecting Dates的更多相关文章

  1. sqlservr (708) 打开日志文件 C:\Windows\system32\LogFiles\Sum\Api.log 时出现错误 -1032 (0xfffffbf8)

    在windows server 2012 standard上新安装好的SQL Server 2014,查看错误日志,发现此报错 sqlservr (708) 打开日志文件 C:\Windows\sys ...

  2. Light OJ 1032 - Fast Bit Calculations(数学)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1032 题目大意:一个十进制数变化为二进制,那么对于这个数,如果连着两个二进制位 ...

  3. 1032: [JSOI2007]祖码Zuma

    链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1032 Description 这是一个流行在Jsoi的游戏,名称为祖玛.精致细腻的背景,外加神 ...

  4. 解剖SQLSERVER 第四篇 OrcaMDF里对dates类型数据的解析(译)

    解剖SQLSERVER 第四篇  OrcaMDF里对dates类型数据的解析(译) http://improve.dk/parsing-dates-in-orcamdf/ 在SQLSERVER里面有几 ...

  5. loj 1032 数位dp

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1032 思路:数位dp, 采用记忆化搜索, dp[pos][pre][have] 表示 ...

  6. PAT乙级 1032. 挖掘机技术哪家强(20)

    1032. 挖掘机技术哪家强(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 为了用事实说明挖掘机技术到底 ...

  7. [MySQL] SQL_ERROR 1032解决办法

    一.缘由: 在主主同步的测试环境,由于业务侧没有遵循同一时间只写一个点的原则,造成A库上删除了一条数据,B库上在同时更新这条数据. 由于异步和网络延时,B的更新event先到达A端执行,造成A端找不到 ...

  8. 1032 - A-B 组合数学

    http://www.ifrog.cc/acm/problem/1032 1032 - A-B Time Limit:1s Memory Limit:128MByte Submissions:680S ...

  9. POJ 1269 Intersecting Lines --计算几何

    题意: 二维平面,给两条线段,判断形成的直线是否重合,或是相交于一点,或是不相交. 解法: 简单几何. 重合: 叉积为0,且一条线段的一个端点到另一条直线的距离为0 不相交: 不满足重合的情况下叉积为 ...

随机推荐

  1. Js处理数据——前端分页工具

    这几天有小伙伴讨论起了分页的相关问题,这里我也简单讲下前端如何简单便捷的利用Js(库)写出优雅,好用的分页工具. 分页是个很简单又超多接触的技术点,粗略来讲分如下两种: 真分页--每次根据页码.页大小 ...

  2. ipad ------ 与iPhone的差别

    1. 差异 iPhone是手机,iPad.iPad Mini是平板电脑 iPhone和iPad开发的区别 屏幕的尺寸 \分辨率 UI元素的排布 \设计 键盘 API 屏幕方向的支持 … … 2. iP ...

  3. 支持HTML5 SqlLite的AndroidApp

    简介: 想要建立一个支持HTML5的Android App; 这个HTML5的程序需要使用本地存储,特别是sqllite; 用eclipse创建了一个app,这个app默认在res/layout建了两 ...

  4. 如何通过SNMP的OID识别不同厂商的设备

    众所周知,SNMP作为通用的网络协议常用于系统监控之中,那么如何借助SNMP来识别不同厂商的设备呢? 事实上,在SNMP的OID树状图中专门有一个节点用于识别各不同的厂商,这个节点是: iso(1)  ...

  5. hdu 4751

    一道很简单的题,不过在比赛的时候没有写出来: 刚刚看到这个题,我以为是一个图论题,后来发现其实就是一个暴力的题: 用bfs,因为一个人与他不认识的人肯定不会在一个集合,如果判断出现冲突则分配失败,否则 ...

  6. ubuntu系统下创建软件桌面快捷方式

    转自ubuntu系统下创建软件桌面快捷方式 默认情况下,ubuntu会将自动安装的软件快捷方式保存在/usr/share/applications目录下,如果我们要创建桌面快捷方式,只需要右键-复制- ...

  7. [LeetCode] Super Ugly Number (Medium)

    Super Ugly Number 最后WA没做出来. typedef long long int64; #define MAXBOUND 10000000 class Solution { publ ...

  8. 【转】Xcode7.1环境下上架iOS App到AppStore 流程 (Part 三)

    原文网址:http://www.cnblogs.com/ChinaKingKong/p/4964745.html 前言部分 part三 部分主要讲解 Xcode关联绑定发布证书的配置.创建App信息. ...

  9. Sharepoint 2010 之 WebPart

    转:http://blog.csdn.net/bestbadgod/article/details/6895542 Sharepoint系列的博客,都是我个人自学过程中的点滴的积累,毕竟没做过C#及A ...

  10. 进军es6(2)---解构赋值

    本该两周之前就该总结的,但最近一直在忙校招实习的事,耽误了很久.目前依然在等待阿里HR面后的结果中...但愿好事多磨!在阿里的某轮面试中面试官问到了es6的掌握情况,说明es6真的是大势所趋,我们更需 ...