当前位置:网站首页>【总结向】个人赛补题 POJ - 3041 Asteroids &CodeForces - 173B Chamber of Secrets
【总结向】个人赛补题 POJ - 3041 Asteroids &CodeForces - 173B Chamber of Secrets
2022-06-10 11:55:00 【sophilex】
POJ - 3041 Asteroids
大意:
N×N (1≤N≤500) 的网格,其中有 K (1≤K≤10000) 颗小行星。每次能够发射一道光束,将某行或者某列上的所有小行星轰成灰烬。希望发射的光束数量尽可能少。问发射的光束最少数量是多少?
思路:
没想到时那么那么那么裸的二分图匹配。。。
一直没有想到将每一个点的列和行作为二部图的两个顶点。
如果想到了这个的话,那其实就是要求一个图的最小覆盖,也就是最大匹配了。
然后匈牙利算法套板子即可。(有匈牙利谁还要写dinic。。。)
两小时罚坐买个教训
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll long long
const ll N=1e4+10;
struct ty{
ll t,next;
}edge[N<<1];
ll cnt=0;
ll head[N];
ll n,m;
ll a,b;
void add(ll a,ll b)
{
edge[++cnt].t=b;
edge[cnt].next=head[a];
head[a]=cnt;
}
ll t[N];
ll df[N];//匹配时间
ll match[N];//匹配对象
bool f(ll u,ll tim)
{
for(int i=head[u];i!=-1;i=edge[i].next)
{
ll y=edge[i].t;
if(df[y]==tim) continue;
df[y]=tim;
if(!match[y]||f(match[y],tim))
{
match[y]=u;
return 1;
}
}
return 0;
}
int main()
{
memset(head,-1,sizeof head);
cin>>n>>m;
ll ti=0;
for(int i=1;i<=m;++i)
{
cin>>a>>b;
add(a,b);
//add(b,a);
}
ll ans=0;
for(int i=1;i<=n;++i)
{
if(f(i,++ti)) ans++;
}
cout<<ans<<endl;
return 0;
} 事实上下一题也是同样的问题(一场比赛踩在同一个坑里两次也是没谁了)
大意:
初始在第一行,目标最后一行,问最少需要几个'#'进行转弯
思路:
一开始想到了最短路,但是建图的时候选择了最莽的方式。。。
我把每一行每一列的所有点两两连边,再把起点与第一行的所有点连接,把终点与最后一行的所有点连接,然后跑dijstra。苦哈哈敲了一百四十多行,超时了。。。然后花了半小时把T调成了wa
没谁了
跟上一题一样,如果选择将每一行/每一列缩成一个点的话,mp【i】【j】有一个石柱,就意味着可以从第i行跳到第j列,那么就是求第一行到第n行的最短路。代码就灰常简单了。
只是不知道为什么,我用链式前向星还是T,换成vector反而过了???
不懂。。。
#include<bits/stdc++.h>
#include<map>
#include<queue>
using namespace std;
#define ll int
#define lowbit(x) x&(-x)
const ll N=1010;
vector<ll> vt[N<<2];
ll vis[2020];
ll dis[2020];
ll n,m;
priority_queue<pair<ll,ll>> q;
inline void dij()
{
for(int i=1;i<=n+m;++i) dis[i]=1e9;
dis[1]=0;
q.push(make_pair(0,1));
while(!q.empty())
{
ll ty=q.top().second;
q.pop();
if(vis[ty]++) continue;
for(int i:vt[ty])
{
ll y=i;
if(vis[y]) continue;
if(dis[y]<=dis[ty]+1) continue;
//cout<<edge[i].l<<endl;
dis[y]=dis[ty]+1;
if(y==n) return;
q.push(make_pair(-dis[y],y));
}
}
}
char a;
char mp[N][N];
signed main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>m;
//memset(head,-1,sizeof head);
ll num=0;
for(int i=1;i<=n;++i)
{
cin>>(mp[i]+1);
}
for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
//cout<<mp[i][j];
if(mp[i][j]=='#')
{
vt[i].push_back(j+n);
vt[j+n].push_back(i);
}
}
// cout<<endl;
}
dij();
if(dis[n]<=1000000) cout<<dis[n];
else cout<<-1;
return 0;
}总结:图论问题有时要考虑将行和列进行压缩,特别是当问题针对图中的某些点时
边栏推荐
猜你喜欢

web开发发展趋势,web计划开发

2022 CISCN初赛 Satool

Sqlsessionfactory and sqlsession details

La poignée d'enseignement de la station B vous apprend à utiliser le masque yolov5 pour tester les éléments de l'enregistrement le plus complet (apprentissage profond / détection d'objets / pythorch)

The teaching staff at station B will teach you how to use the most complete record of the mask detection items of yolov5 (in-depth learning / target detection / pytorch)

web端开发,web开发选型

Transfomer自实现与官方库

【论文泛读】 知识蒸馏:Distilling the knowledge in a neural network

线性代数的本质6 逆矩阵、列空间与零空间

如何编写产品营销策划方案
随机推荐
你对PHP数据类型或者其他编程语言的数据类型了解多少呢
4.25 million budget bidding: centralized procurement of onsite maintenance services for Oracle, teledb, telepg and other core system databases of Jiangsu Telecom
【 ten thousand people single wooden bridge 】 how to arrange life in that summer after the college entrance examination?
Clip usage
Transfomer components and pytoch
Amateurs don't ask for help, drag and drop for 30 seconds to make the cover image
API如何检测安全配置是否有错误?
并发bug之源(一)-可见性
Testing ovn manually based on LXD (by quqi99)
Product milestones in May 2022
"Forget to learn again" shell Basics - 29. Awk built-in variables
数据在内存中的存储方式
[PaperNote] Web3 Direction
Transfomer各组件与Pytorch
[WIP] Openstack Masakari (by quqi99)
搜狐员工遭遇工资补助诈骗 黑产与灰产有何区别 又要如何溯源?
Clip usage
聊聊消息中间件(1),AMQP那些事儿
list.remove(index)返回flase,移除失败
国际档案日|瀚高数据库以科技赋能数字档案建设