CF583A Asphalting Roads
题意
给定 \(n\),\(n^2\) 为上级规定的工期,每条路有两条路等待修建,请你划定一个施工方案。
分析
发现 \(n\) 的范围并不大,所以我们开两个桶记录是否被修建,如果修建过了,那么跳过;否则就铺路。
我们完全可以一边读入一边输出,因为其顺序未改变,可以跑到最优解 \(\rm NO.2\)。
具体请看看代码
//2021/8/23
#include <iostream>
#include <cstdio>
#define debug(c) cerr<<#c<<" = "<<c<<endl
namespace Newstd
{
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0' || ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
{
x=x*10+ch-'0';ch=getchar();
}
return x*f;
}
inline void print(int x)
{
if(x<0)
{
putchar('-');x=-x;
}
if(x>9)
{
print(x/10);
}
putchar(x%10+'0');
}
}
using namespace Newstd;
using namespace std;
const int ma=55;
bool h[ma],v[ma];
int main(void)
{
int n;
scanf("%d",&n);
for(register int i=1;i<=n*n;i++)
{
int H,V;
scanf("%d%d",&H,&V);
if(h[H]==false && v[V]==false)
{
printf("%d ",i);//如果没有修建就开始铺
h[H]=true;//标记
v[V]=true;//标记
}
}
return 0;
}

浙公网安备 33010602011771号