A1016 | 磨人的大模擬
阿新 • • 發佈:2018-01-14
style pan ++ iso set bre amp one div
這題寫得頭暈……明天我再評價
#include <stdio.h> #include <memory.h> #include <math.h> #include <string> #include <vector> #include <set> #include <stack> #include <queue> #include <algorithm> #include <map> #define I scanf #define OL puts #define O printf #defineView CodeF(a,b,c) for(a=b;a<c;a++) #define FF(a,b) for(a=0;a<b;a++) #define FG(a,b) for(a=b-1;a>=0;a--) #define LEN 1010 #define MAX 0x06FFFFFF #define V vector<int> using namespace std; set<string> printTitle; typedef struct Record{ string name; int month,dd,hh,mm; int isOn; Record(){} Record(const Record& o){ name=o.name;month=o.month;dd=o.dd;hh=o.hh;mm=o.mm;isOn=o.isOn; } }Record; Record info[LEN]; int rate[24]; int one_day_bill=0; void init_one_day_bill(){ int i; FF(i,24){ one_day_bill+=60*rate[i]; } } bool cmp(Record a,Record b){ /* if(a.name<b.name) return true; else if(a.mouth<b.mouth) return true; else if(a.dd<b.dd) return true; else if(a.hh<b.hh) return true; else if(a.mm<b.mm) return true; return false;*/ if(a.name!=b.name) return a.name<b.name; else if(a.month!=b.month) return a.month<b.month; else if(a.dd!=b.dd) return a.dd<b.dd; else if(a.hh!=b.hh) return a.hh<b.hh; else return a.mm<b.mm; } void diff(Record a,Record b,int& minute,int& money){ // minute=b.mm-a.mm+(b.hh-a.hh)*60+(b.dd-a.dd)*24*60; // int i; // money=0; // if(a.dd!=b.dd) // money+=(b.dd-a.dd)*one_day_bill; // if(a.hh==b.hh) money=minute*rate[a.hh]; // else{ // for(i=a.hh;i<=b.hh;i++){ // if(i==a.hh) money+=(60-a.mm)*rate[i]; // else if(i==b.hh) money+=(b.mm)*rate[i]; // else money+=(60)*rate[i]; // } // } Record tmp=a; minute=0;money=0; while(tmp.dd<b.dd || tmp.hh< b.hh || tmp.mm < b.mm){ minute++; money+=rate[tmp.hh]; tmp.mm++; if(tmp.mm>=60){ tmp.mm=0; tmp.hh++; } if(tmp.hh>=24){ tmp.hh=0; tmp.dd++; } } } int main(){ freopen("d:/input/A1016.txt","r",stdin); int n,i; FF(i,24){ scanf("%d",&rate[i]); } init_one_day_bill(); scanf("%d",&n); FF(i,n){ char buffer[100]; I("%s",buffer); I("%d:%d:%d:%d",&info[i].month,&info[i].dd,&info[i].hh,&info[i].mm); info[i].name=buffer; I("%s",buffer); if(string(buffer)=="on-line") info[i].isOn=1; else info[i].isOn=0; } sort(info,info+n,cmp); int on=0,off,next; while(on<n){ int needPrint=0; next=on; while(next<n && info[next].name==info[on].name){ if(needPrint==0 && info[next].isOn){ needPrint=1; }else if(needPrint==1 && info[next].isOn==0){ needPrint=2; } next++; } // printf("%d\n",needPrint); if(needPrint<2){ on=next; continue; } int allMoney=0; O("%s %02d\n",info[on].name.c_str(),info[on].month); while(on<next){ while(on<next-1 && !(info[on].isOn&&info[on+1].isOn==0)) on++; off=on+1; if(off==next){ on=next; break; } Record a=info[on],b=info[off]; int minute; int money; diff(a,b,minute,money); allMoney+=money; O("%02d:%02d:%02d %02d:%02d:%02d %d $%.2lf\n",a.dd,a.hh,a.mm,b.dd,b.hh,b.mm,minute,money/100.); on=off+1; } O("Total amount: $%.2lf\n",allMoney/100.); } return 0; }
A1016 | 磨人的大模擬