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 |
大水题,碎觉去(其实這個題有個問題,就是如果要输出y=73并且roundup到75的时猴,74输出什么?估计木有這種数据吧!)#include <iostream> #include <stdio.h> using namespace std; int floor5(int n){ for(int i = n-1; ; i--){ if(i%5 == 0) return i; } } int ceil5(int n){ for(int i = n+1; ; i++){ if(i%5 == 0) return i; } } void printDent(int n, int dent){ if(dent == 2){ if(n < 10) printf(" "); printf("%d", n); } else{ printf("%d", n); } } int main() { int cnt = 0; while(1){ int a, b; scanf("%d%d", &a, &b); if(a == 0 && b == 0) break; cnt++; int gs = 0; int wellX[10000], wellY[10000]; printf("OIL FIELD %d\n", cnt); int maxX = a, maxY = b, minX = a, minY = b; int mn[95], mx[95] = {0}; bool has[95] = {0}; for(int i = 1; i <= 94; i++) mn[i] = 100; has[a] = 1; mx[a] = mn[a] = b; wellX[gs] = a, wellY[gs] = b; gs++; while(1){ int c, d; scanf("%d%d", &c, &d); if(c == -1 && d == -1) break; if(maxX < c) maxX = c; if(minX > c) minX = c; if(maxY < d) maxY = d; if(minY > d) minY = d; has[c] = 1; if(mn[c] > d) mn[c] = d; if(mx[c] < d) mx[c] = d; wellX[gs] = c, wellY[gs] = d; gs++; } int minXB = floor5(minX), maxXB = ceil5(maxX), minYB = floor5(minY), maxYB = ceil5(maxY); bool canDraw = 1; if(maxXB - minXB > 70 || maxYB - minYB > 20){ canDraw = 0; } int minLen = 2147483647, arg = -1; for(int plc = minY; plc <= maxY; plc++){ int lgth = 0; for(int j = minX; j <= maxX; j++){ if(!has[j]) continue; if(plc < mn[j]) lgth += (mx[j]-plc); else if(plc > mx[j]) lgth += (plc-mn[j]); else lgth += (mx[j]-mn[j]); } if(lgth < minLen){ minLen = lgth; arg = plc; } } if(!canDraw){ printf("Map is too big to draw for pipeline at %d\n", arg); continue; } char tu[100][100]; for(int i = minXB+1; i < maxXB; i++){ for(int j = minYB+1; j < maxYB; j++){ tu[i][j] = '.'; } } for(int j = minXB+1; j < maxXB; j++) tu[j][arg] = '*'; for(int i = minX; i <= maxX; i++){ if(!has[i]) continue; if(arg < mn[i]){ for(int j = arg+1; j < mx[i]; j++) tu[i][j] = '*'; } else if(arg > mx[i]){ for(int j = mn[i]+1; j < arg; j++) tu[i][j] = '*'; } else{ for(int j = mn[i]+1; j < mx[i]; j++) tu[i][j] = '*'; } } for(int i = 0; i < gs; i++){ tu[wellX[i]][wellY[i]] = '@'; } int dent = (maxYB > 5)? 2 : 1; printDent(maxYB, dent); for(int i = 0; i <= maxXB-minXB; i++){ if(i%5==0) printf("+"); else printf("-"); } printf("\n"); for(int i = maxYB-1; i > minYB; i--){ if(i%5==0) { printDent(i, dent); printf("+"); } else{ for(int j = 0; j < dent; j++) printf(" "); printf("|"); } for(int j = minXB+1; j < maxXB; j++){ printf("%c", tu[j][i]); } if(i%5==0) printf("+"); else printf("|"); printf("\n"); } printDent(minYB, dent); for(int i = 0; i <= maxXB-minXB; i++){ if(i%5==0) printf("+"); else printf("-"); } printf("\n"); for(int i = 0; i < dent; i++) printf(" "); for(int i = minXB; i <= maxXB; i+=5){ printf("%d", i); if(i == maxXB) break; int space = 4 - (i>=10); for(int j = 0; j < space; j++) printf(" "); } printf("\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