【瞎搞】 HDU 3101 The Heart of the Country
比赛时愣是没读懂
题意:有N 个城市 每一个城市都有 val 个 士兵 , 有几条路连接
当敌方攻击你的某个城市时 该城市以及与该城市相连接的城市的士兵总数 要大于 K
不大于 K 该城市就被攻陷。士兵被俘虏 则不能支援别的城市
求最后一共同拥有多少城市不被攻陷。以及士兵总数
思路:先计算该点能支援到的总士兵数
然后将 总数小于 K 的取出 减去相连的城市上的总士兵数
直到剩下的点都大于K
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <time.h>;
#define cler(arr, val) memset(arr, val, sizeof(arr))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define IN freopen ("in.txt" , "r" , stdin);
#define OUT freopen ("out.txt" , "w" , stdout);
typedef long long LL;
const int MAXN = 1032;
const int MAXM = 444;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
vector<int>G[MAXN];
int val[MAXN],vis[MAXN],ans,num,orz[MAXN],man;
void init()
{
for(int i=0; i<MAXN; i++)
G[i].clear();
cler(val,0);
cler(vis,0);
}
int main()
{
int n,k;
//IN;
while(scanf("%d%d",&n,&k),n+k)
{
init();
for(int i=0; i<n; i++)
{
int a,m;
scanf("%d%d",&val[i],&m);
for(int j=0; j<m; j++)
{
scanf("%d",&a);
G[i].push_back(a);
}
}
for(int i=0; i<n; i++)
{
orz[i]=val[i];
for(int j=0; j<G[i].size(); j++)
orz[i]+=val[G[i][j]];
}
ans=0,num=0;
queue<int>q;
for(int i=0; i<n; i++)
if(orz[i]<k)
q.push(i),vis[i]=1;
while(!q.empty())
{
int i=q.front();
q.pop();
for(int j=0; j<G[i].size(); j++)
{
orz[G[i][j]]-=val[i];
if(orz[G[i][j]]<k&&!vis[G[i][j]])
q.push(G[i][j]),vis[G[i][j]]=1;
}
}
for(int i=0; i<n; i++)
if(!vis[i])
num++,ans+=val[i];
printf("%d %d\n",num,ans);
}
return 0;
}
【瞎搞】 HDU 3101 The Heart of the Country的更多相关文章
- HDU 4923 Room and Moor(瞎搞题)
瞎搞题啊.找出1 1 0 0这样的序列,然后存起来,这样的情况下最好的选择是1的个数除以这段的总和. 然后从前向后扫一遍.变扫边进行合并.每次合并.合并的是他的前驱.这样到最后从t-1找出的那条链就是 ...
- URAL 1203. Scientific Conference(瞎搞)
题目链接 本来觉得这不是经典的贪心吗..果断水一次,wa了,看了看discuss,发现貌似不好水,土土的DP了一下,复杂度很高了,又T了...然后想想单调队列,二分什么的...不好往上加,直接搞了标记 ...
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...
- B. Salty Fish Go! -期望题(瞎搞题)
链接:https://www.nowcoder.com/acm/contest/104/B来源:牛客网 题意:A few days ago, WRD was playing a small game ...
- HDU5532 Almost Sorted Array(最长上升子序列 or 瞎搞个做差的数组)
题目链接:点我 题意:给定一个序列,询问是否能删除一个数让它成为非递减或者非递增的序列. 比如说 删除后的序列是1 3 3 5 或者5 3 3 1 或者1 3 5 或者5 3 1 都可以.只要满足删掉 ...
- TOJ3097: 单词后缀 (字典树 or map瞎搞)
传送门 (<---可以点击的~) 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 描述 有些英语单词后缀都是一样的,现在我们需要从给定的一堆单词里 ...
- [乱搞]hdu 6406 Taotao picks apples 笛卡尔树+倍增
题目链接 Problem Description There is an apple tree in front of Taotao's house. When autumn comes, n app ...
- 8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞
B. Cards 题目连接: http://www.codeforces.com/contest/626/problem/B Description Catherine has a deck of n ...
- ubuntu--基础环境瞎搞集合
安装ubuntu系统后有很多东西需要自己瞎搞一下,这里把一些瞎搞的过程记录在这里,方便以后重新装系统后重新配置. 一.安装. 可以在windows下制作启动盘(软碟通),然后开机u盘启动即可安装,预留 ...
随机推荐
- HDU 1251 统计难题 (字符串-Trie树)
统计难题 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单 ...
- iOS进阶面试题----经典10道
OneV‘s Den在博客里出了10道iOS面试题,用他的话是:"列出了十个应聘Leader级别的高级Cocoa/CocoaTouch开发工程师所应该掌握和理解的技术" . 在这 ...
- UVA 10911 Forming Quiz Teams(dp + 集合最优配对问题)
4th IIUC Inter-University Programming Contest, 2005 G Forming Quiz Teams Input: standard input Outpu ...
- ASP.NET - 多级分类
表结构: 表数据: 最终效果: 前端代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehin ...
- 构建基于Jenkins + Github的持续集成环境
搭建持续集成首先要了解什么是持续集成,带着明确的目标去搭建持续集成环境才能让我们少走很多弯路.持续集成(Continuous integration)简称CI,是一种软件开发的实践,可以让团队在持续集 ...
- Thinkphp入门 五 —模型 (49)
原文:Thinkphp入门 五 -模型 (49) [数据库操作model模型] model 模型 数据库操作 tp框架主要设计模式:MVC C:controller 控制器 shop/Li ...
- Socket 心跳包机制总结
跳包之所以叫心跳包是因为:它像心跳一样每隔固定时间发一次,以此来告诉服务器,这个客户端还活着.事实上这是为了保持长连接,至于这个包的内容,是没有什么特别规定的,不过一般都是很小的包,或者只包含包头的一 ...
- POJ2031Building a Space Station (最小生成树之prim)
Problem Description You are a member of the space station engineering team, and are assigned a task ...
- 用XCA(X Certificate and key management)可视化程序管理SSL 证书(3)--创建自己定义的凭证管理中心(Certificate Authority)
在第"用XCA(X Certificate and key management)可视化程序管理SSL 证书(2)---创建证书请求"章节中,我们介绍了怎样用XCA创建SSL证书请 ...
- Eclipse背景和匹配出现单词的一些设置
Eclipse的背景色和关键词的设置这里就不多说了,只说明设置路径: 背景色:[Window]--->[Preference]-->[General]--->[Editors]--- ...