這次CF還是老樣子,以我的水平只能做做水題,不過手速比前幾次快了些......希望以後越來越快^_^ A題:看完啰嗦的題意就清楚了,兩個循環,統計主隊服裝與客隊服裝的相同數...... [cpp] #include <iostream> #include <cstdio> #include <cstring> using namespace std; int n; int home[50],away[50]; int main() { while(cin >> n) { for(int i=0; i<n; i++) { cin >> home[i] >> away[i]; } int cnt = 0; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { if(j != i && home[i] == away[j]) { cnt++; } } } cout << cnt << endl; } return 0; } B題:一串密碼,問最多需要按多少次按鈕才能猜對。如果猜對當前一位,則繼續;如果猜錯,則回到初始位置。 When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens. 列幾個簡單的例子就找到規律了 [cpp] #include <iostream> #include <cstdio> #include <cstring> using namespace std; int main() { int n; while(cin >> n) { int sum = 0; for(int i=1; i<=n; i++) { sum += i * (n-i); } sum += n; cout <<sum <<endl; } return 0; } C題:在一個給定長寬的平面中,找到最長的整數點序列,使得任意兩個點之間距離不為整數。 兩個整數點最短的非整數距離為根號2,橫縱坐標相差1。這樣依次找出的點一定符合要求。 [cpp] #include <iostream> #include <cstdio> #include <cstring> using namespace std; int n, m; int main() { while(cin >> n >> m) { int k = min(n,m)+1; cout <<k <<endl; for(int i=0; i<=k-1; i++) { cout <<i <<' ' << k-i-1 <<endl; } } return 0; }