洛谷 題解 P2645 【斯諾克】
阿新 • • 發佈:2018-11-02
吐槽一下這道題:
資料太水了!!!
請注意,這題如果你考慮了犯規的情況,那麼你的分數。。。可能會和我一樣,只有40分。
也就是說,這是一篇AC不了這道題的題解!!!
現在,我來講一下這道題的正解:
- 兩個變數
less
和color
:less
記錄剩餘顏色為color
的球的個數,且場上沒有顏色比less
小的球。 - 由題意,當場上沒有紅球時,第單數個球必須是紅球
- 當場上有紅球時,第雙數個球必須是綵球,且擊打不消耗個數。
- 當
less
為0
時,less = 0, color++;
給出處理某一個人的虛擬碼:
執行 n 次 { 記錄上次球的顏色 讀入這次球的顏色 如果 (這次球的顏色為 0) { 直接給對方加 4 分 } 否則 如果 (這是第單數個球 並且 紅球沒有打完) { 如果 (這次球的顏色不是 1) { 如果 (這次球的顏色對應的分數比 4 大) { 給對方加上這次球的顏色對應的分數 } 否則 { 給對方加 4 分 } } 否則 { 給自己加 1 分 紅球個數減 1 如果 (已經沒有紅球了) { 顏色加 1 該顏色個數置為 1 } } } else { if ((上次打的不是紅球 && 這次打的顏色比應該打的顏色大) || 這次打了紅球) { 如果 (這次球的顏色對應的分數比 4 大) { 給對方加上這次球的顏色對應的分數 } 否則 { 給對方加 4 分 } } else { 給自己加 這次球的顏色對應的分數 分 如果 (這個不是紅球后面緊隨的球) 該球個數減 1; 如果 (已經沒有 color 顏色的球了) { 顏色加 1 該顏色個數置為 1 } } } }
最終程式碼
/* Name: Z*** Y* (H***Z*** J***L** Middle School, China) Copyright: 航空信奧 Author: 航空信奧 Date: 2018-10-19 Description: the program that can solve snooker */ #include <queue> #include <vector> #include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> using std::max; using std::min; using std::cerr; using std::endl; using std::sort; using std::queue; using std::vector; using std::priority_queue; struct fast_IO { #define fast_IO_all_DEBUG 0 #define fast_IO_read_DEBUG 0 #define fast_IO_write_DEBUG 0 bool __read_sign_LowThan0; char __read_buf_ch; template <typename type> void read(type &res) { __read_sign_LowThan0 = 0; __read_buf_ch = getchar(); while (__read_buf_ch > '9' || __read_buf_ch < '0') { __read_buf_ch = getchar(); if (__read_buf_ch == '-') { __read_sign_LowThan0 = 1; __read_buf_ch = getchar(); break; } } res = (__read_buf_ch & 15); __read_buf_ch = getchar(); while (__read_buf_ch <= '9' && __read_buf_ch >= '0') { res = (res << 3) + (res << 1) + (__read_buf_ch & 15); __read_buf_ch = getchar(); } if (__read_sign_LowThan0) { res = ((~res) + 1); } #if fast_IO_all_DEBUG || fast_IO_read_DEBUG printf("[TEST $ read %d $ ]", res); #endif } } io; #define read io.read #define write io.write #define passing() fprintf(stderr, "passing line [%d] in function %s.\n", __LINE__, __FUNCTION__) #define debug(x) cerr << "[debug] " << #x << " = " << x << endl #define Max_N (107) #define Max_M #define Max_K #define Max_LogN #define Max_LogM #define Max_LogK int n, m, k; #define P 10007 int a[Max_N] = {0}; bool used[Max_N] = {false}; #define FILE int color = 1; int less = 15; void doit(int &n, int &mine, int &your) { int t, las; for (int i = 1; i <= n; i++) { las = t; read(t); if (!t) { your += 4; } else if ((i & 1) && color == 1) { if (t != 1) { if (t > 4) { your += t; } else { your += 4; } } else { mine++; less--; if (less == 0) { color++; less = 1; } } } else { if ((las != 1 && t > color) || t == 1) { if (t > 4) { your += t; } else { your += 4; } } else { mine += t; if (las != 1 && color != 1) less--; if (less == 0) { color++; less = 1; } } } // printf("ball %d: %d:%d [color = %d eith %d in low]\n", t, mine, your, color, less); } } int main() { #ifdef FILE freopen("snooker.in", "r", stdin); freopen("snooker.out", "w", stdout); #endif read(n); read(m); int ansa(0), ansb(0); doit(n, ansa, ansb); doit(m, ansb, ansa); printf("%d %d", ansa, ansb); return 0; }