【2018ACM山东省赛 - B】Bullet(二分 + 二分图匹配,匈牙利算法,卡常)

题干:

Problem Description

In GGO, a world dominated by gun and steel, players are fighting for the honor of being the strongest gunmen. Player Shino is a sniper, and her aimed shot kills one monster at a time. Now she is in an n×nn \times nn×n map, and there are monsters in some grids. Each monster has an experience. As a master, however, Shino has a strange self-restrain. She would kill at most one monster in a column, and also at most one in a row. Now she wants to know how to get max experience, under the premise of killing as many monsters as possible.

Input

The first line contains an integer nnn. (n<=500)
Then n lines follow. In each line there are n integers, and AijAijAij represents the experience of the monster at grid (i,j)(i,j)(i,j). If Aij=0Aij=0Aij=0, there is no monster at grid (i,j)(i,j)(i,j).

The experience is the minimal experience of all the monster which are killed.

It guaranteed that the maximum of the experience of the monster is not larger than 10^9

Output

One integer, the value of max experience.

Sample Input

2
2 0
1 8

Sample Output

2

题目大意:

   就是一个打怪兽的游戏,你可以选择一个位置打怪兽,你可以打很多怪兽,但是每一行或者每一列最多打一个怪兽(和N皇后问题一样),每个位置上的怪兽都有一个权值(二维数组中的值),如果值为0代表这里没有怪兽,你打完怪兽可以获得的经验值为你所有打的怪兽的权值的最小值。问你最大可以获得多大的权值。

解题报告:

   二分这个最小值,然后匈牙利check一下即可。

   这题卡常(其实是复杂度本身就不允许),但是加了优化可以过。

  优化1:memset改for(不过对这种单组样例的可能用处不大)

  优化2:每次二分之后都新建边,这个对二分图的优化较大。

  优化3:可以先离散化数据然后对数据二分,这样降低了二分次数(不过效果并不是很好,甚至500ms变成了900ms)

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 500 + 5;
struct Edge {int to,ne,w;
} e[MAX*MAX];
int tot,head[MAX];void add(int u,int v,int w) {e[++tot].to = v;e[tot].w = w;e[tot].ne = head[u];head[u] = tot;
}
int all,tmp,n,a[MAX][MAX];
int nxt[MAX];
bool use[MAX];
bool find(int x) {for(int j = head[x]; ~j; j = e[j].ne) {int v = e[j].to;if(use[v] == 1) continue;		if(e[j].w < tmp) continue;use[v]=1;if(nxt[v] == 0 || find(nxt[v])) {nxt[v] = x;return 1;}}return 0 ;
}
int match() {
//	memset(nxt,0,sizeof nxt);for(int i = 1; i<=n; i++) nxt[i] = 0;int res = 0;for(int i = 1; i<=n; i++) {for(int i = 1; i<=n; i++) use[i] = 0;if(find(i)) res++;}return res;
}
bool ok(int x) {tmp = x;if(match() == all) return 1;else return 0 ;
}
int main()
{	tot=0;int maxx=0;cin>>n;for(int i = 1; i<=n; i++) head[i] = -1;for(int i = 1; i<=n; i++) {for(int j = 1; j<=n; j++) {scanf("%d",&a[i][j]);maxx=max(maxx,a[i][j]);}}for(int i = 1; i<=n; i++) {for(int j = 1; j<=n; j++) {if(a[i][j]) add(i,j,a[i][j]);}}all = match();if(maxx == 0) {printf("0\n");return 0 ;}int l = 1,r = maxx,mid,ans=0;while(l<=r) {mid=(l+r)>>1;tot=0;for(int i = 1; i<=n; i++) head[i] = -1;for(int i = 1; i<=n; i++) {for(int j = 1; j<=n; j++) {if(a[i][j] >= mid) add(i,j,a[i][j]);}}if(ok(mid)) ans = mid,l = mid+1;else r = mid-1;}printf("%d\n",ans);return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440298.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

13.Data Leakage

本教程是ML系列的一部分。在此步骤中&#xff0c;你将学习什么是data leakage及如何预防它。 What is Data Leakage 数据泄漏是数据科学家需要理解的最重要问题之一。 如果您不知道如何防止它&#xff0c;则会频繁出现泄漏&#xff0c;并且会以最微妙和危险的方式破坏您的模…

0.Overview----Machine Learning

本文为Kaggle Learn的Machine Learning课程的中文翻译&#xff0c;原文链接为&#xff1a;https://www.kaggle.com/learn/machine-learning 1.How Models Work The first step if youre new to machine learning 2.Explore Your Data Load data and set up your environment …

【2018ACM山东省赛 - C】Cities(最小生成树变形优化,贪心思维)

题干&#xff1a; Problem Description There are nnn cities in Byteland, and the ithi_{th}ith​ city has a value aia_iai​. The cost of building a bidirectional road between two cities is the sum of their values. Please calculate the minimum cost of connec…

项目总结1:微信扫码自动识别设备类型并跳转到相应的应用下载页面(apk或App Store)之解决方案

问题分析&#xff1a;普通页面一般无法调用微信的扫一扫接口&#xff0c;从而否定通过微信扫一扫功能给我们判断当前扫码的设备类型。 解决方案&#xff1a;通过应用下载页面自身来获取当前访问的客户端设备类型&#xff08;iPhone、Android、iPad&#xff09;&#xff0c;然后…

《TCP/IP详解》学习笔记(六):UDP 协议

UDP 简要介绍 UDP 是传输层协议&#xff0c;和 TCP 协议处于一个分层中&#xff0c;但是与 TCP 协议不同&#xff0c;UDP 协议并不提供超时重传&#xff0c;出错重传等功能&#xff0c;也就是说其是不可靠的协议。 UDP 协议头 1UDP 端口号 由于很多软件需要用到 UDP 协议&am…

【2018ACM山东省赛 - E】Sequence(树状数组,思维,优化)

题干&#xff1a; We define an element aia_iai​ in a sequence "good", if and only if there exists a j(1≤j<i)j(1\le j < i)j(1≤j<i) such that aj<aia_j < a_iaj​<ai​. Given a permutation ppp of integers from 111 to nnn. Remove …

Apollo自动驾驶入门课程第②讲 — 高精地图

目录 1. 高精地图与传统地图 2. 高精地图与定位、感知规划的关系 2.1 高精地图用于定位 2.2 高精地图用于感知 2.3 高精地图用于规划 3. Apollo高精度地图与构建 3.1 Apollo高精地图 3.2 Apollo高精地图的构建 本文转自微信公众号&#xff1a; Apollo开发者社区 原创&a…

项目总结2:ionic3开发跨平台App如何设置和替换应用图标及启动图

前言&#xff1a; 和原生开发一样&#xff0c;ionic官方提供的设置方式也很简单&#xff0c;只不过多了一个步骤&#xff1a;基于ionic命令的方式自动修改全局的配置文件config.xml。 设置或替换应用图标和应用启动图&#xff1a; 把UI提供的图标拿过来改成特定的名称"i…

【2018ACM山东省赛 - G】Games(Nim博弈 + dp)

题干&#xff1a; Problem Description Alice and Bob are playing a stone game. There are nnn piles of stones. In each turn, a player can remove some stones from a pile (the number must be positive and not greater than the number of remaining stones in the …

LeetCode刷题实战(13):Roman to Integer

题目描述&#xff1a; 13 Roman to Integer 49.5%Easy Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D …

项目总结3:ionic3开发的App在启动过程中部分手机出现白屏或黑屏问题之终极解决方案

问题场景&#xff1a;采用ionic3开发的App&#xff0c;当项目比较大的时候&#xff0c;会出现部分真机设备在启动的过程中有白屏或黑屏的情况。 原因预测&#xff1a;个别手机&#xff0c;尤其是安卓手机的性能比较差&#xff0c;App在启动后进入首页或登录页前的初始化工作还…

1.Intro to Deep Learning and Computer Vision

Intro 这是Kaggle深度学习教育课程的第一课。 在本课程结束后&#xff0c;您将了解卷积。 卷积是计算机视觉&#xff08;以及许多其他应用程序&#xff09;中深度学习模型的基本构建块。 之后&#xff0c;我们将很快开始使用世界一流的深度学习模型。 Lesson [1] from IPy…

【POJ - 2253】Frogger(floyd,或 部分瓶颈生成树的最大边)

题干&#xff1a; 湖中有n块石头&#xff0c;编号从1到n&#xff0c;有两只青蛙&#xff0c;Bob在1号石头上&#xff0c;Alice在2号石头上&#xff0c;Bob想去看望Alice&#xff0c;但由于水很脏&#xff0c;他想避免游泳&#xff0c;于是跳着去找她。但是Alice的石头超出了他…

SpringMVC常用的视图接口分类及实现类

SpringMVC中常用的视图接口分类及对应的实现类&#xff1a; URL资源视图&#xff1a;InternalResourceView、JstlView 文档视图&#xff1a;AbstractExcelView、AbstractPdfView 报表视图&#xff1a;ConfigurableJsperReportsView等JasperReports报表技术的视图 JSON视图&…

2.Building Models from Convolutions

Intro 这是深度学习课程的第2课 在本课程结束时&#xff0c;您将了解如何将卷积结合起来&#xff0c;以实现计算机视觉中的超人成就。 Lesson [1] from IPython.display import YouTubeVideo YouTubeVideo(ToBPiUlLFEY, width800, height450) Keep Going 现在你理解了模…

*【POJ - 2796】 Feel Good (前缀和优化+单调栈维护)

题干&#xff1a; Feel Good Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 12409 Accepted: 3484Case Time Limit: 1000MS Special Judge Description Bill is developing a new mathematical theory for human emotions. His recent investigations are dedi…

SpringMVC配置视图的直接映射view-controller命名空间

通常情况下&#xff0c;如果直接通过url来访问具体的视图会报404错误&#xff0c;这个时候最容易想到的解决办法是通过转发或重定向机制&#xff0c;也就说走一遍目标控制器方法拦截一次。但是最好的方法是配置视图的直接映射关系。 <mvc: view-controller path"url访…

【nyoj-456】 邮票分你一半 (dp,0-1背包的中点问题)

题干&#xff1a; 邮票分你一半 时间限制&#xff1a;1000 ms | 内存限制&#xff1a;65535 KB 难度&#xff1a;3 描述 小珂最近收集了些邮票&#xff0c;他想把其中的一些给他的好朋友小明。每张邮票上都有分值&#xff0c;他们想把这些邮票分成两份&#xff0c;并且使…

Angular中父子组件传值@Input @Output @ViewChild最全面最简单的总结

父组件传递给子组件&#xff1a; 值传递方式&#xff1a;Input既可以传递数据也可以传递方法 传递数据&#xff08;不举例了&#xff09;传递方法 // 父组件定义方法 parentRun(){alert(这是父组件的 run 方法); } 调用子组件时传入当前方法&#xff08;是传递方法不是调用方…

《TCP/IP详解》学习笔记(七):广播和多播、IGMP协议

单播&#xff0c;多播&#xff0c;广播的介绍 1单播(unicast) 单播是说&#xff0c;对特定的主机进行数据传送。例如给某一个主机发送 IP 数据包。这时候&#xff0c;数据链路层给出的数据头里面是非常具体的目的地址&#xff0c;对于以太网来说&#xff0c;就是网卡的 MAC 地…