程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> codeforce #164 div2

codeforce #164 div2

編輯:C++入門知識

這次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;   }    

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved