【瞎搞】 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盘启动即可安装,预留 ...
随机推荐
- HTML - HTML Commonly Used Character Entities
HTML Entities Some characters are reserved in HTML. It is not possible to use the less than (<) o ...
- 3.跟我学solr---使用solrj加入索引
上一章讲了怎么使用solr admin向solrserver加入索引,Solr 是一个独立的企业级搜索应用server.它对外提供类似于 Web-service 的 API 接口. 用户能够通过 ht ...
- 服务确定(服务类收货ML81N)
FUNCTION zrfc_mm005. *"---------------------------------------------------------------------- * ...
- linux命令:find
先上例子: find ./*_src -type f | xargs grep -ils "date" 在指定的那些文件夹下面,递归寻找包含“date” 字符串的普通文件. fin ...
- 64位win7旗舰版搭建apache+php+mysql开发环境[转]
我建议把apache.php.mysql都安装在一个文件夹中,比如:web/apache.web/php.web/mysql 1.安装apache2.2.25,请查看win7下安装VC9版本的ap ...
- 通过cl_dd_document来实现在ALV中输出标题头
*&---------------------------------------------------------------------* *& Report ZTEST_LIN ...
- 基于visual Studio2013解决面试题之0306打印第一次只出现一次的字符
题目
- Google Ads Encryption Key
aes | floyd's Google Ads Encryption Key
- cp命令的实现
#include <unistd.h> #include <fcntl.h> #include <stdlib.h> #define BUFFERSIZE 4096 ...
- vs2005及以上版本的程序分发问题
我们使用vs2005及以上版本编译的应用程序(C/C++),在客户机器运行时,会出现: “由于应用程序的配置不正确,应用程序未能启动,重新安装应用程序可能会纠正这个问题” 那么,我们怎么解决这个问题呢 ...