码迷,mamicode.com
首页 > 其他好文 > 详细

A1016 | 磨人的大模拟

时间:2018-01-14 21:19:20      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:ack   amp   include   color   ext   using   amount   scan   dprint   

这题写得头晕……明天我再评价

技术分享图片
#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
#define F(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;
}
View Code

 

A1016 | 磨人的大模拟

标签:ack   amp   include   color   ext   using   amount   scan   dprint   

原文地址:https://www.cnblogs.com/TQCAI/p/8284117.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!