sdutEconomic phone calls

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2368

我也不知道 这份代码算不算DP 之前写的那份长长的长长的dp死活过不了 可能太长了 bug就太多了。。

这个是根据必须保留的来算哪些可以删除 哪些必须保留

3种情况

当前这个号的日期是‘-’号,‘+’号直接不能删除 继续循环

1、 若比前一个不能删除的(pre)大 也就是它们是同一年份的 如果下一个也就是i+1 的年份比i大 也就是它三是一年份的 或者 i+1的年份比pre小或相等 当前i可以删除。

2、若比pre小 不同年份 如果i+1的年份比i大而且比pre小于等于 当前i可以被删除。

3、不符合上述2种情况 不能被删除 pre为当前i;

View Code
 1 #include <iostream>
 2 #include<cstdio>
 3 #include<string.h>
 4 #define INF 100000
 5 using namespace std;
 6 struct node
 7 {
 8     int a,b,c,d;
 9     char s1[30],s2[30];
10 }q[1011];
11 int num;
12 int judge(node x,node y)
13 {
14     if(x.a>y.a)
15     return 1;
16     else
17     if(x.a<y.a)
18     return 0;
19     else
20     if(x.b>y.b)
21     return 1;
22     else
23     if(x.b<y.b)
24     return 0;
25     else
26     if(x.c>y.c)
27     return 1;
28     else
29     if(x.c<y.c)
30     return 0;
31     else
32     if(x.d>y.d)
33     return 1;
34     else
35     if(x.d<y.d)
36     return 0;
37     else
38     return -1;
39 }
40 int main()
41 {
42     int i,j,k,n,m,yy,pre;
43     while(scanf("%d",&n)&&n)
44     {
45 
46         int g = 0;
47         num = 0;
48         scanf("%d:%d:%d:%d%s%s",&q[1].a,&q[1].b,&q[1].c,&q[1].d,&q[1].s1,&q[1].s2);
49         for(i = 2; i <= n ; i++)
50         {
51             scanf("%d:%d:%d:%d%s%s",&q[i].a,&q[i].b,&q[i].c,&q[i].d,&q[i].s1,&q[i].s2);
52         }
53         q[n+1].a =0,q[n+1].b=0,q[n+1].c=0,q[n+1].d=0;
54         i = 1;
55         while(q[i].s2[0]=='-')
56         {
57             num++;
58             i++;
59         }
60         node pre = q[i];
61         for(i=i+1 ; i <= n; i++)
62         {
63             if(q[i].s2[0]=='+')
64             {
65                 pre = q[i];
66                 continue;
67             }
68             if(judge(q[i],pre)>0&&(judge(q[i+1],pre)<=0||judge(q[i+1],q[i])>0))
69               {
70                   num++;
71               }
72            else
73            if(judge(q[i],pre)==0&&judge(q[i],q[i+1])==0&&judge(q[i+1],pre)<=0)
74            {
75                num++;
76            }
77            else
78            {
79                pre = q[i];
80            }
81         }
82         printf("%d\n",n-num);
83     }
84     return 0;
85 }

 

posted @ 2012-08-29 11:34  _雨  阅读(146)  评论(0编辑  收藏  举报