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

    哎,水平依旧很烂,只能做出第一道很水的题。

    第一道题很简单,分析最初的位置,分成三种情况,仔细一点就没问题了,也算比较快的就提交了。

    http://community.topcoder.com/stat?c=problem_solution&rm=313696&rd=15171&pm=11964&cr=23038076

    第二道题比赛的时候没想清楚,比完赛之后发现了方法,其实就是二分图匹配问题,想清楚之后代码也就好写了,可惜一个小时竟然都没有想出来,要不然就是涨积分的大好时机了啊。

     1 #include <iostream>
     2 #include <string>
     3 #include <vector>
     4 #include <queue>
     5 #include <algorithm>
     6 #include <map>
     7 #include <math.h>
     8 #include <cstdlib>
     9 #include <cstring>
    10 using namespace std;
    11 
    12 const int MAXN = 100;
    13 class PointyWizardHats {
    14 public:
    15     int uN, vN; // u, v 数目,要初始化!!!
    16     bool g[MAXN][MAXN]; // g[i][j] 表示xi与yj相连
    17     int xM[MAXN], yM[MAXN]; // 输出量
    18     bool chk[MAXN]; //  辅助量检查某轮y[v]是否被check
    19     bool SearchPath(int u) {
    20         int v;
    21         for (v = 0; v < vN; v++)
    22             if (g[u][v] && !chk[v]) {
    23                 chk[v] = true;
    24                 if (yM[v] == -1 || SearchPath(yM[v])) {
    25                     yM[v] = u;
    26                     xM[u] = v;
    27                     return true;
    28                 }
    29             }
    30         return false;
    31     }
    32     int MaxMatch() {
    33         int u, ret = 0;
    34         memset(xM, -1, sizeof(xM));
    35         memset(yM, -1, sizeof(yM));
    36         for (u = 0; u < uN; u++)
    37             if (xM[u] == -1) {
    38                 memset(chk, false, sizeof(chk));
    39                 if (SearchPath(u))
    40                     ret++;
    41             }
    42         return ret;
    43     }
    44 
    45     bool isok(int th, int tr, int bh, int br) {
    46         double b1 = double(th) / double(tr);
    47         double b2 = double(bh) / double(br);
    48         if (br > tr && b1 > b2) {
    49             return true;
    50         }
    51         return false;
    52     }
    53 
    54     int getNumHats(vector<int> topHeight, vector<int> topRadius,
    55             vector<int> bottomHeight, vector<int> bottomRadius) {
    56         uN = topHeight.size();
    57         vN = bottomRadius.size();
    58         int i, j;
    59         for (i = 0; i < MAXN; i++)
    60             for (j = 0; j < MAXN; j++)
    61                 g[i][j] = false;
    62 
    63         for (i = 0; i < uN; i++)
    64             for (j = 0; j < vN; j++) {
    65                 if (isok(topHeight[i], topRadius[i], bottomHeight[j],
    66                         bottomRadius[j])) {
    67                     g[i][j] = true;
    68                 }
    69             }
    70 
    71         int res = MaxMatch();
    72         return res;
    73 
    74     }
    75 };

    第三题还没有思路,继续思考............

  • 相关阅读:
    LeetCode 234. 回文链表
    LeetCode 237. 删除链表中的节点
    LeetCode 20. 有效的括号( 括号配对 )
    堆栈操作合法性
    堆排序
    最大堆
    快速排序
    Bzoj1497 [NOI2006]最大获利
    Bzoj1001 [BeiJing2006]狼抓兔子
    Bzoj2716 [Violet 3]天使玩偶
  • 原文地址:https://www.cnblogs.com/kakamilan/p/2583868.html
Copyright © 2011-2022 走看看