首页 > 其他分享 >P2825 [HEOI2016/TJOI2016] 游戏 与 P10945 Place the Robots

P2825 [HEOI2016/TJOI2016] 游戏 与 P10945 Place the Robots

时间:2024-08-29 15:40:04浏览次数:4  
标签:typedef P2825 ll Robots long P10945 char pair define

本文中的机器人同炸弹,主要是题目描述不同,两道题目做法是本质相同的。

思路:

先说一下没有墙怎么办,那么当一个位置放了机器人之后,这个机器人所在的行和列是不能继续放置的。

那么发现行和列几乎是独立的,考虑建二分图,若 \((i,j)\) 能放一个机器人,那么给 \(i \to j\) 建一条边。

那么答案就是这个二分图的最大匹配,这样每个匹配的就代表着一个机器人所放的位置。

现在再考虑有墙的情况,有墙时,机器人所放的激光无法穿透过去,则在墙另外一边依旧可能可以放置机器人。

发现墙就是把行或列分为了几个部分,每个部分互不干扰,则考虑每遇到墙,就新起一行表示当前位置到下一个墙或者这一行的末尾的放块;列同理。

直接跑匈牙利算法即可。

P2825 [HEOI2016/TJOI2016] 游戏 Code:
#include<bits/stdc++.h>
#define Add(x,y) (x+y>=mod)?(x+y-mod):(x+y)
#define lowbit(x) x&(-x)
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll>>
#define iip pair<pair<ll,ll>,ll>
#define ppii pair<pair<ll,ll>,pair<ll,ll>>
#define fi first
#define se second
#define full(l,r,x) for(auto it=l;it!=r;it++) (*it)=x
#define Full(a) memset(a,0,sizeof(a))
#define open(s1,s2) freopen(s1,"r",stdin),freopen(s2,"w",stdout);
#define For(i,l,r) for(int i=l;i<=r;i++)
#define _For(i,l,r) for(int i=r;i>=l;i--)
using namespace std;
typedef double db;
typedef unsigned long long ull;
typedef long long ll;
const ll N=2505;
inline ll read(){
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')
          f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
inline void write(ll x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x>9)
	  write(x/10);
	putchar(x%10+'0');
}
inline char get(){
    char c;
    while((c=getchar())!='*'&&c!='x'&&c!='#');
    return c;
}
ll n,m,id,ans,s1,s2;
ll a[N],f[N];
ll h[N][N];
char s[N][N];
vector<ll> E[N];
void add(ll u,ll v){
	E[u].push_back(v);
}
bool dfs(ll u){
	for(auto v:E[u]){
		if(f[v]==id)
		  continue;
		f[v]=id;
		if(!a[v]||dfs(a[v])){
			a[v]=u;
			return 1;
		}
	}
	return 0;
}
void Match(){
	for(int i=1;i<=s1;i++){
		id=i;
		if(dfs(i))
		  ans++;
	}
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
		s[i][j]=get();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j]=='#')
			  continue;
			if(s[i][j-1]=='#'||j==1)
			  ++s1;
			h[i][j]=s1;
		}
	}
	for(int j=1;j<=m;j++){
		for(int i=1;i<=n;i++){
			if(s[i][j]=='#')
			  continue;
			if(s[i-1][j]=='#'||i==1)
			  ++s2;
			if(h[i][j]&&s[i][j]=='*')
			  add(h[i][j],s2);	
		}
	}
	Match();
	write(ans);
	return 0;
}
P10945 Place the Robots Code:
#include<bits/stdc++.h>
#define Add(x,y) (x+y>=mod)?(x+y-mod):(x+y)
#define lowbit(x) x&(-x)
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll>>
#define iip pair<pair<ll,ll>,ll>
#define ppii pair<pair<ll,ll>,pair<ll,ll>>
#define fi first
#define se second
#define full(l,r,x) for(auto it=l;it!=r;it++) (*it)=x
#define Full(a) memset(a,0,sizeof(a))
#define open(s1,s2) freopen(s1,"r",stdin),freopen(s2,"w",stdout);
#define For(i,l,r) for(int i=l;i<=r;i++)
#define _For(i,l,r) for(int i=r;i>=l;i--)
using namespace std;
typedef double db;
typedef unsigned long long ull;
typedef long long ll;
const ll N=2505;
inline ll read(){
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')
          f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
inline void write(ll x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x>9)
	  write(x/10);
	putchar(x%10+'0');
}
inline char get(){
    char c;
    while((c=getchar())!='*'&&c!='o'&&c!='#');
    return c;
}
ll T,n,m,cnt,id,ans,s1,s2;
ll a[N],f[N];
ll h[N][N];
char s[N][N];
vector<ll> E[N];
void add(ll u,ll v){
	E[u].push_back(v);
}
bool dfs(ll u){
	for(auto v:E[u]){
		if(f[v]==id)
		  continue;
		f[v]=id;
		if(!a[v]||dfs(a[v])){
			a[v]=u;
			return 1;
		}
	}
	return 0;
}
void Match(){
    memset(f,0,sizeof(f));
    memset(a,0,sizeof(a));
	for(int i=1;i<=s1;i++){
		id=i;
		if(dfs(i))
		  ans++;
	}
}
void solve(){
	n=read(),m=read();
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
		s[i][j]=get();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j]=='#')
			  continue;
			if(s[i][j-1]=='#'||j==1)
			  ++s1;
			h[i][j]=s1;
		}
	}
	for(int j=1;j<=m;j++){
		for(int i=1;i<=n;i++){
			if(s[i][j]=='#')
			  continue;
			if(s[i-1][j]=='#'||i==1)
			  ++s2;
			if(h[i][j]&&s[i][j]=='o')
			  add(h[i][j],s2);	
		}
	}
	Match();
    printf("Case :%lld\n",++cnt);
	write(ans);
    putchar('\n');
    For(i,1,max(s1,s2))
      E[i].clear();
    s1=s2=ans=0;
}
int main(){
    T=read();
    while(T--)
      solve();
	return 0;
}

标签:typedef,P2825,ll,Robots,long,P10945,char,pair,define
From: https://www.cnblogs.com/rgw2010/p/18386806

相关文章

  • 提升SEO与网站可爬性 :动态生成sitemaps和robots.txt文件
    本文由ChatMoney团队出品在现代Web开发中,搜索引擎优化(SEO)是网站成功的关键因素之一。搜索引擎通过网络爬虫来索引网页,而sitemaps和robots.txt文件则是帮助这些爬虫更好地理解和索引网站内容的重要工具。sitemaps简介Sitemap(站点地图)是一种XML文件,它包含了网站上的所有URL以......
  • 动态生成sitemaps和robots.txt文件:提升SEO与网站可爬性
    本文由ChatMoney团队出品在现代Web开发中,搜索引擎优化(SEO)是网站成功的关键因素之一。搜索引擎通过网络爬虫来索引网页,而sitemaps和robots.txt文件则是帮助这些爬虫更好地理解和索引网站内容的重要工具。sitemaps简介Sitemap(站点地图)是一种XML文件,它包含了网站上的所有URL以......
  • Topcoder SRM647-Div1-Lv2 CtuRobots
    涉及知识点:动态规划题意有\(n\(\leq500)\)个机器人,每个机器人的价格为\(cost_i\(\leq10^4)\),油箱容量为\(cap_i\(\leq10^9)\),一单位燃料可以走一单位距离,你可以给购买的机器人编号,机器人\(k\)可以给机器人\(k+1\)补充燃料,但是任意时刻机器人的燃料不能超过其油箱......
  • 初中英语优秀范文100篇-096My views on robots entering the classroom-我对机器人进
    PDF格式公众号回复关键字:SHCZFW096记忆树1Withthedevelopmentoftechnology,ithasbecomepossibleforrobotstoentertheclassroom.翻译随着科技的发展,机器人进入课堂已成为可能。简化记忆课堂句子结构It"是形式主语,真正的主语是不定式短语forrobotsto......
  • CF1045G AI robots题解
    题目链接:洛谷或者CF本题考虑转化为cdq分治模型对于cdq分治来说,只需要考虑左边对右边的影响,那我们要考虑该怎样设置第一维度的左右对象。很显而易见的是抛开\(q\)限制而言,我们着眼于,如何让双方互相看到的严格条件转化为只需要关注单体看见。考虑什么情况下只需要一方看到......
  • robots.txt禁止收录协议写法
    1. 什么是robots.txt?robots.txt 是网站和搜索引擎的协议的纯文本文件。当一个搜索引擎蜘蛛来访问站点时,它首先爬行来检查该站点根目录下是否存在robots.txt,如果存在,根据文件内容来确定访问范围,如果没有,蜘蛛就沿着链接抓取。robots.txt 放在项目的根目录下。2. robots.txt......
  • Web_XCTF_WriteUp | Training-WWW-Robots
    题目分析标题大致翻译:训练WWW网络爬虫。场景内部文段大致翻译:在这个小小的训练挑战中,您将学习Robots_exclusion_standard(网络爬虫排除标准)。robots.txt文件用于网络爬虫检查它们是否被允许抓取和索引您的网站或仅部分网站。有时,这些文件揭示了目录结构,而不是保护内......
  • robots后台泄露
     [^来源:ctfshow-vip题目限免  考点:robots.txt文件泄露后台路径WP1.题目 唉,就是一道简单robots文件泄露,但是我为什么要写这个呢,因为我真的大可爱,一直搁那/robots,,,,,我说怎么没反应,,,无语,,,是robots.txt文件啊,文件我不加后缀名,我服了,我记得之前也是做过两次这种的题......
  • AtCoder Beginner Contest 216 H Random Robots
    洛谷传送门AtCoder传送门下文令\(n\)为原题中的\(K\),\(m\)为原题中的\(N\)。首先概率转方案数,最后除\(2^{nm}\)即可。考虑一个指数级暴力:枚举每个bot的终点\(y_i\)(因为存在不能相交的限制,需要满足\(y_1<y_2<\cdots<y_n\)),相当于为每个bot选一个\((0,x_i)......
  • 谷歌优化之如何编写和提交 robots.txt 文件
    您可以使用robots.txt文件控制抓取工具可以访问您网站上的哪些文件。robots.txt文件应位于网站的根目录下。因此,对于网站 www.example.com,robots.txt文件的路径应为 www.example.com/robots.txt。robots.txt是一种遵循漫游器排除标准的纯文本文件,由一条或多条规则组成。每条......