되는대로 살자

[올림피아드 기출문제&풀이] 본문

2009~2014/C/C++

[올림피아드 기출문제&풀이]

malu 2011. 12. 12. 17:27
#include <stdio.h>

struct flower
{
int openmonth;
int openday;
int closemonth; 
int closeday;
}flower[100000];
int main()
{
long n;
int curmonth=3,curday=1,maxmonth=0,maxday=0,visit[100000],maxpos;
int flowercnt=0,i,noflowerchk;
scanf("%d",&n);
for(i=0;i<n;i++) {
scanf("%d %d %d %d",&flower[i].openmonth,&flower[i].openday,
&flower[i].closemonth,&flower[i].closeday);
}
while(curmonth<12) {
noflowerchk=1;
for(i=0;i<n;i++) { 
if(visit[i]!=1) { 
if(((curmonth>flower[i].openmonth) ||
(curmonth==flower[i].openmonth&&curday>=flower[i].openday))&&
((flower[i].closemonth>maxmonth) ||
(flower[i].closemonth==maxmonth&&flower[i].closeday>=maxday))) {
maxmonth=flower[i].closemonth;
maxday=flower[i].closeday;
maxpos=i;
noflowerchk=0;
}
}
}
if(noflowerchk==1) {
printf("0");
return 0;
}
curmonth=maxmonth;
curday=maxday;
flowercnt++;
visit[maxpos]=1;
}
printf("%d",flowercnt);
}