E - M‘s Solution atcoder M-SOLUTIONS Programming Contest 2020

部署运行你感兴趣的模型镜像

https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_e

考虑一个点,要么被x覆盖,要么被y覆盖,要么没被覆盖,所以我们只需要枚举每个点的3个状态就行了。

因为要覆盖一个点只需要一条铁路,至于新增的那条怎么影响其他点不用管,因为其他点的情况也被枚举了,所以其实一个点是被横的覆盖,他也有可能被其他点的竖的覆盖了,但对求答案无所谓

比赛的时候再判断函数里面排序加滑动窗口求答案3^n*nlogn TLE了,赛后加了个2^n*nlogn的预处理,直接处理出x选择情况时候对x的答案和y选择情况时对y的答案,然后再判断函数里面就只要扫一遍n了

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;

const int maxl=3e5+10;
const ll inf=1ll<<60;

int n,m,cas,k,cnt,totx,toty;
int st[maxl],numx[maxl],numy[maxl];
int xdis[1<<15][16],ydis[1<<15][16];
int xlen[1<<15],ylen[1<<15];
ll c[maxl],ans[maxl];
struct node
{
	int x,y,val,id;
}a[maxl],bx[maxl],by[maxl];
vector<int> tmpx,tmpy;
char s[maxl];
bool inx[maxl],iny[maxl]; 


inline void prework()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{	
		scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].val);
		a[i].id=i;
		bx[i]=node{a[i].x,a[i].y,a[i].val,i};
		by[i]=node{a[i].x,a[i].y,a[i].val,i};
	}
	for(int i=0;i<=n;i++)
		ans[i]=inf;
} 

inline bool cmpx(const node &a,const node &b)
{
	return a.x<b.x;
}

inline bool cmpy(const node &a,const node &b)
{
	return a.y<b.y;
}

inline ll dis(int x,int y)
{
	return abs(x-y);
}

inline void jug(int sx,int sy)
{
	ll tmp=0;int len=xlen[sx]+ylen[sy];
	for(int i=1;i<=n;i++)
		tmp+=1ll*min(xdis[sx][i],ydis[sy][i])*a[i].val;
	ans[len]=min(ans[len],tmp);
}

inline void dfs(int k,int sx,int sy)
{
	if(k>n)
		jug(sx,sy);
	else
	{
		dfs(k+1,sx,sy);
		dfs(k+1,sx|(1<<(k-1)),sy);
		dfs(k+1,sx,sy|(1<<(k-1)));
	}
}

inline void mainwork()
{
	sort(bx+1,bx+1+n,cmpx);
	sort(by+1,by+1+n,cmpy);
	int up=1<<n;
	for(int s=0;s<up;s++)
	{
		tmpx.clear();tmpx.push_back(0);
		tmpy.clear();tmpy.push_back(0);
		for(int i=1;i<=n;i++)
		if((s>>(i-1))&1)
		{
			tmpx.push_back(a[i].x);
			tmpy.push_back(a[i].y);
		}
		sort(tmpx.begin(),tmpx.end());
		sort(tmpy.begin(),tmpy.end());
		tmpx.erase(unique(tmpx.begin(),tmpx.end()),tmpx.end());
		tmpy.erase(unique(tmpy.begin(),tmpy.end()),tmpy.end());
		int id=0;xlen[s]=tmpx.size();
		for(int i=1;i<=n;i++)
		{
			while(id+1<xlen[s] && dis(bx[i].x,tmpx[id+1])<dis(bx[i].x,tmpx[id]))
				++id;
			xdis[s][bx[i].id]=dis(bx[i].x,tmpx[id]);
		}
		id=0;ylen[s]=tmpy.size();
		for(int i=1;i<=n;i++)
		{
			while(id+1<ylen[s] && dis(by[i].y,tmpy[id+1])<dis(by[i].y,tmpy[id]))
				++id;
			ydis[s][by[i].id]=dis(by[i].y,tmpy[id]);
		}
		--xlen[s];--ylen[s];
	}
	dfs(1,0,0);
	for(int i=n;i>=0;i--)
	{	
		if(ans[i]!=inf)
			break;
		ans[i]=0;
	}
}

inline void print()
{
	for(int i=0;i<=n;i++)
		printf("%lld\n",ans[i]);
}

int main()
{
	int t=1;
	//scanf("%d",&t);
	for(cas=1;cas<=t;cas++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

 

您可能感兴趣的与本文相关的镜像

Seed-Coder-8B-Base

Seed-Coder-8B-Base

文本生成
Seed-Coder

Seed-Coder是一个功能强大、透明、参数高效的 8B 级开源代码模型系列,包括基础变体、指导变体和推理变体,由字节团队开源

One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. Input The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. Output Print a single integer — the number of problems the friends will implement on the contest. Examples Inputcopy Outputcopy 3 1 1 0 1 1 1 1 0 0 2 Inputcopy Outputcopy 2 1 0 0 0 1 1 1 Note In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.c++
最新发布
09-30
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值