Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
wa wa wa....wa wa wa.....#include "stdafx.h" #include "string.h" #include "math.h" #include <queue> #include <algorithm> #include <iostream> #define MinN(x,y) ((x)<(y)?(x):(y)) #define MaxN(x,y) ((x)>(y)?(x):(y)) #define _clr(a,b) memset(a,b,sizeof(a)) template<class T> void _swap(T& a,T& b) {T temp;temp=a;a=b;b=temp;} template<class T> T _abs(T a) {if(a<0) a=-a;return a;} using namespace std; int Tran(char a[]) { int ans=0; for(int i=0;i<=9;i+=3) { ans*=100; ans+=(a[i]-'0')*10+(a[i+1]-'0'); } return ans; } int cnt[1005],time[1005]; bool important[1005]; int main() { freopen("e:\\1.in","r",stdin); //freopen("e:\\1.out","w",stdout); int temp1; int temp2; bool temp3; int n; char temp_char[25]; while(scanf("%d",&n)&&n!=0) { _clr(cnt,0); _clr(time,0); time[0]=-1; cnt[0]=0; important[0]=false; time[n+1]=-1; //important[n+1]=true; for(int i=1;i<=n;i++) { scanf("%s",temp_char); time[i]=Tran(temp_char); scanf("%s",temp_char); scanf("%s",temp_char); if(temp_char[0]=='+') important[i]=true; else important[i]=false; } for(int i=1;i<=n;i++) { if(important[i]==true) { if(important[i-1]==true) cnt[i]=cnt[i-1]+1; else { if(time[i]<=time[i-1]) cnt[i]=cnt[i-1]+1; else// if(time[i]>time[i-1]) { if(time[i]<=time[i-2]) { temp1=time[i-1]; temp2=cnt[i-1]; temp3=important[i-1]; time[i-1]=time[i-2]; cnt[i-1]=cnt[i-2]; important[i-1]=important[i-2]; time[i]=temp1; cnt[i]=temp2; important[i]=temp3; cnt[i]=cnt[i-1]; } else cnt[i]=cnt[i-1]+1; } } } else { if(time[i]<=time[i-1]) cnt[i]=cnt[i-1]+1; else { if(important[i-1]==false) { temp1=time[i-1]; temp2=cnt[i-1]; temp3=important[i-1]; time[i-1]=time[i-2]; cnt[i-1]=cnt[i-2]; important[i-1]=important[i-2]; if(time[i]>time[i-2]) { time[i]=temp1; } cnt[i]=temp2; } else { if(time[i]>=time[i+1]&&time[i-1]<time[i+1]) { cnt[i]=cnt[i-1]+1; } else { temp1=time[i-1]; temp2=cnt[i-1]; temp3=important[i-1]; time[i-1]=time[i-2]; cnt[i-1]=cnt[i-2]; important[i-1]=important[i-2]; time[i]=temp1; cnt[i]=temp2; important[i]=temp3; } } } } } printf("%d\n",cnt[n]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator