SRM480
250pt:
题意:给定n个网站,以及n个网站的关键词,还有一个危险词库。如果一个网站的关键词中>=th的危险词,那么这个网站便是危险的。同时,他的所有关键词加入危险词库。问,有多少个危险网站。
思路:直接模拟。
code:
#line 7 "InternetSecurity.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; class InternetSecurity
{
public:
vector<string> A[];
bool v[];
vector <string> determineWebsite(vector <string> wbs, vector <string> key, vector <string> dan, int th)
{
for (int i = ; i < key.size(); ++i){
string tmp;
stringstream ss;
A[i].clear();
ss << key[i];
while (ss >> tmp) A[i].PB(tmp);
// cout << A[i][A[i].size() - 1] << endl;
}
set<string> S;
memset(v, , sizeof(v));
for (int i = ; i < dan.size(); ++i) S.insert(dan[i]);
bool keepLooking = true;
while (keepLooking){
keepLooking = false;
for (int i = ; i < key.size(); ++i)
if (!v[i]){
int cnt = ;
for (int j = ; j < A[i].size(); ++j)
if (S.find(A[i][j]) != S.end()) ++cnt;
if (cnt >= th){
keepLooking = true;
v[i] = true;
for (int j = ; j < A[i].size(); ++j)
S.insert(A[i][j]);
}
}
}
vector<string> ans;
ans.clear();
for (int i = ; i < key.size(); ++i)
if (v[i]) ans.PB(wbs[i]);
return ans;
}
};
450pt:
题意:给定一个DAG的客户机及服务器之间的关系,服务器只有入边。现在求在那些边上装一些安全设置,使得所有客户机到服务器至少都有经过一个安全设置的边。
思路:因为是DAG,那么直接对原图进行一边搜索,记录直接点的状态,转移到根状态
code:
#line 7 "NetworkSecurity.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; class NetworkSecurity
{
public:
int n, m, ans;
bool vis[];
vector<string> S, C;
long long S1[];
void dfs(int u){
if (vis[u]) return;
vis[u] = true;
S1[u] = ;
for (int i = ; i < C[u].size(); ++i)
if (C[u][i] == 'Y'){
dfs(i);
S1[u] |= S1[i];
}
for (int i = ; i < S[u].size(); ++i)
if (S[u][i] == 'Y'){
if (!((1LL << i) & S1[u])){
++ans;
S1[u] |= (1LL << i);
}
}
}
int secureNetwork(vector <string> clientCable, vector <string> serverCable)
{
ans = ;
S = serverCable;
C = clientCable;
memset(vis, , sizeof(vis));
for (int i = ; i < S.size(); ++i)
if(!vis[i]) dfs(i);
return ans;
}
};
SRM480的更多相关文章
随机推荐
- python提取分析表格数据
#/bin/python3.4# -*- coding: utf-8 -*- import xlrd def open_excel(file="file.xls"): try: d ...
- java.lang.AbstractMethodError: javax.servlet.jsp.JspFactory.getJspApplicationContext(Ljavax/servlet/ServletContext;)Ljavax/servlet/jsp/JspApplicationContext;
在Tomcat下部署应用时会报这个错误,参考以下这篇博客:http://blog.csdn.net/robinsonmhj/article/details/37653189,删除Tomcat目录下we ...
- Notification 通知传值
通知 是在跳转控制器之间常用的传值代理方式,除了代理模式,通知更方便.便捷,一个简单的Demo实现通知的跳转传值. 输入所要发送的信息 ,同时将label的值通过button方法调用传递, ...
- EXISTS 和 IN 的区别
exists子句的用法 select * from 表1 where exists (select * from 表2 where 表1.列名=表2.列名); exists子句返回的结果并不是从数据库 ...
- serial -1
#include <reg52.h>#include <stdio.h>#define uchar unsigned charsbit LED = P2^2;uchar rec ...
- xcode资源管理
1. 在根目录放图片. UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ok.pn ...
- 前端-关于 Vue 和 React 区别的一些笔记
监听数据变化的实现原理不同 1.Vue 通过 getter/setter 以及一些函数的劫持,能精确知道数据变化,不需要特别的优化就能达到很好的性能 2.React 默认是通过比较引用的方式进行的,如 ...
- Mysql命令drop database:删除数据库
drop命令用于删除数据库. drop命令格式:drop database <数据库名>; 例如,删除名为 xhkdb的数据库:mysql> drop database xhkdb; ...
- SimpleDateFormat转换时间,12,24时间格式[转]
SimpleDateFormat转换时间,12,24时间格式 来自:http://blog.csdn.net/dongguang1082/article/details/4387165 在使用Simp ...
- WebSocket的原理与优缺点
websocket 是长连接,受网络限制比较大,需要处理好重连,比如用户进电梯或电信用户打个电话网断了,这时候就需要重连,如果 ws 一直重连不上,有些较复杂的业务方会不愿意的,是不是还要搞个 htt ...