Codeforces Round 865 (Div. 2) B. Grid Reconstruction

传送门:https://codeforces.com/contest/1816/problem/B

给个题面看看

 题意:给你1-2n个数字放在一个2*n的网格中,从(1,1)走到(2,n)求花费路径的最小值的最大化,定义花费是即花费为a[i]*(-1)^(-1+i)

要使的花费最小,就是要加的大,减的少(开源节流)

#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#define IOS() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define fir(v) (v).first
#define se(v) (v).second
#define pb(x) push_back(x)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define pii pair<int,int>
#define all(a) (a).begin(),(a).end()
#define mp(a,b) make_pair(a,b)
using namespace std;
const int N=1000000;
int a[3][2000006];//数组第二个要开的大一点
bool cmp(int x,int y)
{
	return x>y;
}
signed main()
{
	   IOS();
	   int t ;
	   cin>>t;
	   while(t--){
	   	int n;
	   	cin>>n;
	   	a[1][1]=2*n;//(1,1)的值放最大
	   	for(int i=1;i<=n;i++){
	   		if(i%2==1){
	   			a[2][i]=i;//第二行的奇数位置
	   			a[2][i+1]=i+n;//第二行的偶数位置
			   }
			else {//偶数位置
				a[1][i]=i;//第一行的偶数位置
				a[1][i+1]=i+n;//第一行的奇数位置
			}
		   }
	   	for(int i=1;i<=2;i++){//输出
	   		for(int j=1;j<=n;j++){
	   			cout<<a[i][j]<<" ";
			   }
			   cout<<endl;
		   }
		   
	   }

}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值