zoukankan      html  css  js  c++  java
  • SRM 552 DIV2

    比较悲催,第二道题没调出来,被long long的乘法越界坑了。

    第一道题比较水一些,求四个矩阵中的F数目

     1 #include <iostream>
     2 #include <string>
     3 #include <vector>
     4 #include <cstdlib>
     5 #include <cmath>
     6 #include <map>
     7 #include <algorithm>
     8 #include <list>
     9 #include <ctime>
    10 #include <set>
    11 #include <queue>
    12 using namespace std;
    13 
    14 
    15 class FoxAndFlowerShopDivTwo{
    16 public:
    17     int theMaxFlowers(vector <string> flowers, int r, int c){
    18         int res=0;
    19         int row_n=flowers.size();
    20         int col_n=flowers[0].size();
    21         int counter;
    22         counter=0;
    23         for (int i = 0; i < r; i++)
    24             for (int j = 0; j < col_n; j++) {
    25                 if (flowers[i][j] == 'F')
    26                     counter++;
    27                 res = max(res, counter);
    28             }
    29         counter = 0;
    30         for (int i = 0; i < row_n; i++)
    31             for (int j = 0; j < c; j++) {
    32                 if (flowers[i][j] == 'F')
    33                     counter++;
    34                 res = max(res, counter);
    35             }
    36         counter = 0;
    37         for (int i = r+1; i < row_n; i++)
    38             for (int j = 0; j < col_n; j++) {
    39                 if (flowers[i][j] == 'F')
    40                     counter++;
    41                 res = max(res, counter);
    42             }
    43         counter = 0;
    44         for (int i = 0; i < row_n; i++)
    45             for (int j = c+1; j < col_n; j++) {
    46                 if (flowers[i][j] == 'F')
    47                     counter++;
    48                 res = max(res, counter);
    49             }
    50         return res;
    51     }
    52 };

    第二个,二分搜索

     1 #include <iostream>
     2 #include <string>
     3 #include <vector>
     4 #include <cstdlib>
     5 #include <cmath>
     6 #include <map>
     7 #include <algorithm>
     8 #include <list>
     9 #include <ctime>
    10 #include <set>
    11 #include <queue>
    12 using namespace std;
    13 typedef long long ll;
    14 class FoxPaintingBalls{
    15 public:
    16     bool valid (vector<ll> array,ll average, ll num){
    17         ll sum=0;
    18         for(ll i=0;i<3;i++){
    19             array[i]=array[i]-average*num;//就是被这个坑了
    20             if(array[i]<0)
    21                 return false;
    22             sum=sum+array[i];
    23         }
    24         if(num>sum)
    25             return false;
    26         return true;
    27     }
    28 
    29     long long theMax(long long R, long long G, long long B, int N){
    30         if(1==N)
    31             return R+G+B;
    32         ll myn=(ll) N;
    33         ll total=(myn+1)*myn;
    34         int judge=N%3;
    35         ll big,small;
    36         total=total/2;
    37         ll res=0;
    38         if(1==judge){
    39             big=total/3+1;
    40             small=total/3;
    41         }else{
    42             big=small=total/3;
    43         }
    44 
    45         vector<ll> array;
    46         array.push_back(R);
    47         array.push_back(G);
    48         array.push_back(B);
    49         if(1==judge){
    50             ll left=0;
    51             ll right=3000000000000000001LL;
    52             ll mid;
    53             while(left<right){
    54                 mid=left+(right-left)/2;
    55                 if(valid(array,small,mid)){
    56                     left=mid+1;
    57                 }else{
    58                     right=mid;
    59                 }
    60             }
    61             res=left-1;
    62 
    63         }else{
    64             res=min(R/big,min(G/big,B/big));
    65         }
    66         return res;
    67 
    68 
    69     }
    70 };

    第三道题应该算是总结规律的题,这尼玛太蛋疼了

    这哥们写的比较清楚http://blog.csdn.net/acm_cxlove/article/details/7877067

  • 相关阅读:
    ZOJ 1002 Fire Net (火力网)
    UVa OJ 117 The Postal Worker Rings Once (让邮差只走一圈)
    UVa OJ 118 Mutant Flatworld Explorers (变体扁平世界探索器)
    UVa OJ 103 Stacking Boxes (嵌套盒子)
    UVa OJ 110 MetaLoopless Sorts (无循环元排序)
    第一次遇到使用NSNull的场景
    NSURL使用浅析
    从CNTV下载《小小智慧树》
    NSDictionary and NSMutableDictionary
    Category in static library
  • 原文地址:https://www.cnblogs.com/kakamilan/p/2644184.html
Copyright © 2011-2022 走看看