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 |
看错题了,是从X到X+Y不是到Y。。。又贡献一次哇#include <stdio.h> #include <iostream> #include <cstdlib> #include <cstring> #include <vector> #include <algorithm> using namespace std; struct rule{ int src; int dest; int beg; int end; }byBeg[110], byEnd[110]; void print(int n){ if(n<10) printf("000"); else if(n<100) printf("00"); else if(n<1000) printf("0"); printf("%d",n); } bool cmpBeg(const rule& r1, const rule& r2){ return r1.beg < r2.beg; } bool cmpEnd(const rule& r1, const rule& r2){ return r1.end < r2.end; } int target[10000]; int rNum; void init(){ for(int i = 0; i < 10000; i++){ target[i] = 0; } rNum = 0; } int mn(int x, int y){return (x<y)? x: y;} int main(){ printf("CALL FORWARDING OUTPUT\n"); int n; scanf("%d",&n); for(int ii = 1; ii <= n; ii++){ printf("SYSTEM %d\n",ii); init(); int src, beg, end, dest; while(1){ //cout << "hehe" << endl; scanf("%d",&src); //cout << src << endl; if(!src) { break;} scanf("%d%d%d",&beg, &end, &dest); byBeg[rNum].src = src, byBeg[rNum].beg = beg, byBeg[rNum].end = beg+end+1, byBeg[rNum].dest = dest; byEnd[rNum] = byBeg[rNum]; rNum++; } //cout << "hehe" << endl; sort(byBeg, byBeg+rNum, cmpBeg); sort(byEnd, byEnd+rNum, cmpEnd); int begPos = 0, endPos = 0; int jd = -1; while(1){ int sj, call; scanf("%d",&sj); if(sj==9000) break; scanf("%d",&call); jd++; while(jd <= sj){ int nextJd = sj+1; if(begPos < rNum) nextJd = mn(nextJd, byBeg[begPos].beg); if(endPos < rNum) nextJd = mn(nextJd, byEnd[endPos].end); if(nextJd == sj+1) break; jd = nextJd; while(endPos < rNum && byEnd[endPos].end == jd){ target[byEnd[endPos].src] = 0; endPos++; } while(begPos < rNum && byBeg[begPos].beg == jd){ target[byBeg[begPos].src] = byBeg[begPos].dest; begPos++; } } jd = sj; int dest = target[call]; if(dest == 0) dest = call; else{ bool cycle = 0; while(target[dest] != 0){ dest = target[dest]; if(dest == call){ cycle = 1; break; } } if(cycle) dest = 9999; } printf("AT "); print(sj); printf(" CALL TO "); print(call); printf(" RINGS "); print(dest); printf("\n"); } } printf("END OF OUTPUT\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