zoukankan      html  css  js  c++  java
  • SRM480

    250pt:

    题意:给定n个网站,以及n个网站的关键词,还有一个危险词库。如果一个网站的关键词中>=th的危险词,那么这个网站便是危险的。同时,他的所有关键词加入危险词库。问,有多少个危险网站。

    思路:直接模拟。

    code:

     1 #line 7 "InternetSecurity.cpp"
     2 #include <cstdlib>
     3 #include <cctype>
     4 #include <cstring>
     5 #include <cstdio>
     6 #include <cmath>
     7 #include <algorithm>
     8 #include <vector>
     9 #include <string>
    10 #include <iostream>
    11 #include <sstream>
    12 #include <map>
    13 #include <set>
    14 #include <queue>
    15 #include <stack>
    16 #include <fstream>
    17 #include <numeric>
    18 #include <iomanip>
    19 #include <bitset>
    20 #include <list>
    21 #include <stdexcept>
    22 #include <functional>
    23 #include <utility>
    24 #include <ctime>
    25 using namespace std;
    26 
    27 #define PB push_back
    28 #define MP make_pair
    29 
    30 #define REP(i,n) for(i=0;i<(n);++i)
    31 #define FOR(i,l,h) for(i=(l);i<=(h);++i)
    32 #define FORD(i,h,l) for(i=(h);i>=(l);--i)
    33 
    34 typedef vector<int> VI;
    35 typedef vector<string> VS;
    36 typedef vector<double> VD;
    37 typedef long long LL;
    38 typedef pair<int,int> PII;
    39 
    40 
    41 class InternetSecurity
    42 {
    43         public:
    44         vector<string> A[400];
    45         bool v[400];
    46         vector <string> determineWebsite(vector <string> wbs, vector <string> key, vector <string> dan, int th)
    47         {
    48                for (int i = 0; i < key.size(); ++i){
    49                      string tmp;
    50                      stringstream ss;
    51                      A[i].clear();
    52                      ss << key[i];
    53                      while (ss >> tmp)  A[i].PB(tmp);
    54                   //   cout << A[i][A[i].size() - 1] << endl;       
    55                }
    56                set<string> S;
    57                memset(v, 0, sizeof(v));
    58                for (int i = 0; i < dan.size(); ++i) S.insert(dan[i]);
    59                bool keepLooking = true;
    60                while (keepLooking){
    61                      keepLooking = false;
    62                      for (int i = 0; i < key.size(); ++i)
    63                         if  (!v[i]){
    64                               int cnt = 0;
    65                               for (int j = 0; j < A[i].size(); ++j)
    66                                  if (S.find(A[i][j]) != S.end()) ++cnt;
    67                               if (cnt >= th){
    68                                    keepLooking = true;
    69                                    v[i] = true;
    70                                    for (int j = 0; j < A[i].size(); ++j)
    71                                        S.insert(A[i][j]);     
    72                               }   
    73                         }   
    74                }
    75                vector<string> ans;
    76                ans.clear();
    77                for (int i = 0; i < key.size(); ++i)
    78                    if (v[i]) ans.PB(wbs[i]);
    79                return ans;
    80         }
    81 };
    View Code

    450pt:

    题意:给定一个DAG的客户机及服务器之间的关系,服务器只有入边。现在求在那些边上装一些安全设置,使得所有客户机到服务器至少都有经过一个安全设置的边。

    思路:因为是DAG,那么直接对原图进行一边搜索,记录直接点的状态,转移到根状态

    code:

     1 #line 7 "NetworkSecurity.cpp"
     2 #include <cstdlib>
     3 #include <cctype>
     4 #include <cstring>
     5 #include <cstdio>
     6 #include <cmath>
     7 #include <algorithm>
     8 #include <vector>
     9 #include <string>
    10 #include <iostream>
    11 #include <sstream>
    12 #include <map>
    13 #include <set>
    14 #include <queue>
    15 #include <stack>
    16 #include <fstream>
    17 #include <numeric>
    18 #include <iomanip>
    19 #include <bitset>
    20 #include <list>
    21 #include <stdexcept>
    22 #include <functional>
    23 #include <utility>
    24 #include <ctime>
    25 using namespace std;
    26 
    27 #define PB push_back
    28 #define MP make_pair
    29 
    30 #define REP(i,n) for(i=0;i<(n);++i)
    31 #define FOR(i,l,h) for(i=(l);i<=(h);++i)
    32 #define FORD(i,h,l) for(i=(h);i>=(l);--i)
    33 
    34 typedef vector<int> VI;
    35 typedef vector<string> VS;
    36 typedef vector<double> VD;
    37 typedef long long LL;
    38 typedef pair<int,int> PII;
    39 
    40 
    41 class NetworkSecurity
    42 {
    43         public:
    44         int n, m, ans;
    45         bool vis[1010];
    46         vector<string> S, C;
    47         long long S1[200];
    48         void dfs(int u){
    49              if (vis[u]) return;
    50              vis[u] = true;
    51              S1[u] = 0;
    52              for (int i = 0; i < C[u].size(); ++i)
    53                   if (C[u][i] == 'Y'){
    54                         dfs(i);
    55                         S1[u] |= S1[i];
    56                   }
    57              for (int i = 0; i < S[u].size(); ++i)
    58                  if (S[u][i] == 'Y'){
    59                       if (!((1LL << i) & S1[u])){
    60                           ++ans;
    61                           S1[u] |= (1LL << i);
    62                       }
    63                  }
    64         }
    65         int secureNetwork(vector <string> clientCable, vector <string> serverCable)
    66         {
    67                 ans = 0;
    68                 S = serverCable;
    69                 C = clientCable;
    70                 memset(vis, 0, sizeof(vis));
    71                 for (int i = 0; i < S.size(); ++i)
    72                      if(!vis[i]) dfs(i);
    73                 return ans;
    74         }
    75 };
    View Code
  • 相关阅读:
    USB设备的一些概念
    DDK 的一些笔记
    Android cannot access localhost?
    Run or Debug Android application 弹出了SDL_app:emulator.exe 的错误 说我指令引用的内存不能为可写的
    Cannot refer to a nonfinal variable music inside an inner class defined in a different method
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.clm.activity/com.clm.activity
    Failed to install helloworld.apk on device 'emulator5554': timeout
    SortedMap接口
    Automatic Target Mode: Preferred AVD '2.3.3' is not available. Launching new emulator.
    Only one expression can be specified in the select list when the subquery is not introduced with EXI
  • 原文地址:https://www.cnblogs.com/yzcstc/p/3627103.html
Copyright © 2011-2022 走看看