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

codeforce #165 div2

編輯:C++入門知識

這次做的不夠理想,過程磕磕絆絆,C題還是倒在第42個樣例上(看了下WA的人,就數我最悲劇)......   A題:求所給角度(0--180)能否組成正多邊形.。 套用內角公式(n - 2)* 180 / n ,則 a == 180.0 - (360.0/j) j為邊數   [cpp]   #include <iostream>   #include <cstdio>      using namespace std;      int main()   {       int n;       double a;       while(cin >> n)       {           for(int i=0; i<n; i++)           {               cin >> a;               int ok = 0;               for(int j=2; j<=360; j++)               {                   if(a == 180.0 - (360.0/j))                   {                       ok = 1;                       break;                   }               }               if(ok == 1)               {                   cout << "YES" << endl;               }               else                   cout << "NO" << endl;           }       }       return 0;   }       B題: 原先有一系列板塊編號1-n,如有某個板塊更新信息則占據首位,其他後移。給出刷新後位置由前到後的板塊編號,問一定更新信息的板塊有幾個。   相鄰兩個板塊i,i+1如果編號i > 編號i+1。說明板塊i一定更新了,板塊i+1卻不一定。而板塊i更新,排在板塊i前面的,也是必定更新了。 這樣問題就變成找最後一個滿足板塊編號i > 編號i+1的。   [cpp]   #include <iostream>   #include <cstdio>      using namespace std;      int a[100005];      int main()   {       int n;       while(cin >> n)       {           int t=0;           for(int i=1; i<=n; i++)           {               cin >>  a[i];           }           for(int i=1; i<n; i++)           {               if(a[i] > a[i+1])                   t = i;           }           cout << t << endl;       }       return 0;   }       C題: C. Magical Boxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes. From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure: Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes. Input The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct. Output Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p. Sample test(s) input 2 0 3 1 5 output 3 input 1 0 4 output 1 input 2 1 10 2 2 output 3 Note Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture. In the second test case, we can put all four small boxes into a box with side length 2.   有一堆大大小小的箱子,小的能放大的裡面,求另取一個邊長最短的箱子,將這些箱子裝下。具體規則就看題吧... 想法是將已有箱子按照邊長由小到大排序,一個循環中,將較小的放入較大些的,如果較小的剩余,則剩余的小的箱子換算成較大的;如此遞推, 再枚舉能裝下已有最大箱子最小的邊長的箱子。 雖然考慮到了k范圍實在是太大了而加上if(2 * box[i+1].len - 2 * box[i].len <= 32)剔除,但沒注意等於 32也是超過范圍的。所以去掉等號,就行了。 [cpp]  #include <iostream>   #include <cstdio>   #include <cmath>   #include <algorithm>   using namespace std;      struct BOX   {       long long len,num;   } box[100005];      bool cmp(BOX a, BOX b)   {       return a.len < b.len;   }      int main()   {       int n;       while(cin >> n)       {           for(int i=0; i<n; i++)           {               cin >> box[i].len >> box[i].num;           }           sort(box,box+n,cmp);              for(int i=0; i<n-1; i++)           {               if(2 * box[i+1].len - 2 * box[i].len < 32)               {                   int t = ceil(box[i].num*1.0/((1 << (2*box[i+1].len -2 * box[i].len)))) - box[i+1].num;                   if(t > 0)                       box[i+1].num += t;               }           }           long long t = box[n-1].num;           int i;           for(i=1;; i++)           {               if(1 << (2 * i) >= t)                   break;           }           cout << i + box[n-1].len << endl;       }       return 0;   }     賽後發現C題是div1的第一題,可見去div1就是掛零的節奏......長路漫漫啊!!!      

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