Abs Problem

Abs Problem

Time Limit: 2 Seconds       Memory Limit: 65536 KB       Special Judge

Alice and Bob is playing a game, and this time the game is all about the absolute value!

Alice has N different positive integers, and each number is not greater than N. Bob has a lot of blank paper, and he is responsible for the calculation things. The rule of game is pretty simple. First, Alice chooses a number a1 from the N integers, and Bob will write it down on the first paper, that's b1. Then in the following kth rounds, Alice will choose a number ak (2 ≤ k ≤ N), then Bob will write the number bk=|ak-bk-1| on the kth paper. |x| means the absolute value of x.

Now Alice and Bob want to kown, what is the maximum and minimum value of bN. And you should tell them how to achieve that!

Input

The input consists of multiple test cases;

For each test case, the first line consists one integer N, the number of integers Alice have. (1 ≤ N ≤ 50000)

Output

For each test case, firstly print one line containing two numbers, the first one is the minimum value, and the second is the maximum value.

Then print one line containing N numbers, the order of integers that Alice should choose to achieve the minimum value. Then print one line containing N numbers, the order of integers that Alice should choose to achieve the maximum value.

Attention: Alice won't choose a integer more than twice.

Sample Input
2
Sample Output
1 1
1 2
2 1

Author:  ZHANG, Ruixiang

Source: ZOJ Monthly, August 2014

题目大意: 输入N,序列a是1~N任意序的序列,序列b={bk | bk=|ak-bk-1|,k∈[1,N]},求bn能取得最大值和最小值,并求其对应的序列a?

当 N =2时 
最小  1  2
最大  1  2
那么N=3呢!
对于最大我们很容易得到  N = 2 最小后加上 N 就OK了。
即 :最大  1 2 3
那么最小怎么得到了呢! 难道是在  N =2 最大值后加上 N 构成1 2 3 吗?显然不是不然就跟最小的不就一样了。
但可以肯定的就是即使不是也有一定的联系毕竟是最大的减去最大的对吧!
这么考虑下
当 N =2时
最大  1  2  可以看成是 N = 1 的最小值后加上 N 构成1 2
所以 当 N = 2 时最大 1  2 的 2 前面的数是由N = 1最小确定的也是确定的,可以看成 X
那么到底怎么得到 N = 3时的最小呢!
由上面的推导我们可以将当N = 2的最大改为  X  2  即  X  N-1
考怒这两组数据
X   N-1  N     得到 X+1
X    N  N-1    得到 X-1 
很显然 最小的应该是  X-1
依次推下去便得到这样的关系:
N 的最大值来自 N-1 的最小值后加上 N
N 的最小值来自 N-1 的最大值前N-2 个数加上 N 再加上 N-1  即:X   N-1  N
还有就是: N=2 时
最小  1  2
最大  2  1
按照这种关系往下推也能得出正解,比赛时就是取的这个初始值。可能是因为最大时 1 2 和2 1都相等吧!我也解释不清。
看了队友的方法:
最小值就倒序   最大值就N前面数倒序然后在其后加上N
其实我试了下,最小值也可以在队友的前一组数的最大值序的 N-2 位置 插入 N 
也即 X  N  N-1
总之 X为 N-2 的最小序,X  N  N-1  就满足 N序的最小序
最大序就是 N-1 的最小序后加 N
最小序0——>0     最小序2——>0 2 1     最小序4——>0 2 1 4 3  
最小序1——>0 1   最小序3——>0 1 3 2   最小序5——>0 1 3 2 5 4

#include<cstdio>
#include<iostream>
#include<iterator>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
#define inf 1<<29
int a[50010], b[50010];
int main()
{
	int n, Min, Max;	
	while (scanf("%d", &n) != EOF)
	{	
		Min = 0; Max = 0;
		a[1] = 1; a[2] = 2;
		b[1] = 2; b[2] = 1;
		for (int i = 3; i <= n; i++)
		{
			if (i % 2) { a[i] = i;  b[i] = b[i - 1];  b[i - 1] = i; }
			else       { b[i] = i;  a[i] = a[i - 1];  a[i - 1] = i; }		
		}
		for (int i = 1; i <= n; i++)
		{
			Min = abs(a[i] - Min);
			Max = abs(b[i] - Max);	
		}			
		if (n % 2 == 0)
		{
			printf("%d %d\n", Min, Max);
			for (int i = 1; i <= n; i++)
			{
				if (i == n) printf("%d\n", a[i]);
				else printf("%d ", a[i]);
			}
			for (int i = 1; i <= n; i++)
			{
				if (i == n) printf("%d\n", b[i]);
				else printf("%d ", b[i]);
			}
		}
		else
		{
			printf("%d %d\n", Max, Min);
			for (int i = 1; i <= n; i++)
			{
				if (i == n) printf("%d\n", b[i]);
				else printf("%d ", b[i]);
			}
			for (int i = 1; i <= n; i++)
			{
				if (i == n) printf("%d\n", a[i]);
				else printf("%d ", a[i]);
			}
		}
	}
	return 0;
}

/*

#include<cstdio>
#include<iostream>
#include<iterator>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
#define inf 1<<29
int a[50010], b[50010];
int main()
{
	int n, Min, Max;
	a[1] = 2; a[2] = 1;
	b[1] = 1; b[2] = 3; b[3] = 2;
	for (int i = 4; i <= 50000; i++)
	{
		if (i % 2) { b[i - 1] = i;  b[i] = i - 1; }
		else       { a[i - 1] = i;  a[i] = i - 1; }
	}
	while (scanf("%d", &n) != EOF)
	{
		Min = 0; Max = 0;	
		for (int i = 1; i <= n; i++)
		{	
			if (i == n) Max = abs(i - Max);
			if (n % 2 == 0)
			{
				Min = abs(a[i] - Min);			
				if(i<n) Max = abs(b[i] - Max);
			}
			else
			{
				Min = abs(b[i] - Min);
				if (i < n) Max = abs(a[i] - Max);
			}					
		}
		printf("%d %d\n", Min, Max);
		if (n % 2 == 0)
		{		
			for (int i = 1; i <= n; i++)
			{
				if (i == n) printf("%d\n", a[i]);
				else printf("%d ", a[i]);
			}
			for (int i = 1; i <= n; i++)
			{
				if (i == n) printf("%d\n",n);
				else printf("%d ", b[i]);
			}
		}
		else
		{
			for (int i = 1; i <= n; i++)
			{
				if (i == n) printf("%d\n", b[i]);
				else printf("%d ", b[i]);
			}
			for (int i = 1; i <= n; i++)
			{
				if (i == n) printf("%d\n", n);
				else printf("%d ", a[i]);
			}
		}
	}
	return 0;
}

*/



基于Swin Transformer与ASPP模块的图像分类系统设计与实现 本文介绍了一种结合Swin Transformer与空洞空间金字塔池化(ASPP)模块的高效图像分类系统。该系统通过融合Transformer的全局建模能力和ASPP的多尺度特征提取优势,显著提升了模型在复杂场景下的分类性能。 模型架构创新 系统核心采用Swin Transformer作为骨干网络,其层次化窗口注意力机制能高效捕获长距离依赖关系。在特征提取阶段,创新性地引入ASPP模块,通过并行空洞卷积(膨胀率6/12/18)和全局平均池化分支,实现多尺度上下文信息融合。ASPP输出经1x1卷积降维后与原始特征拼接,有效增强了模型对物体尺寸变化的鲁棒性。 训练优化策略 训练流程采用Adam优化器(学习率0.0001)和交叉熵损失函数,支持多GPU并行训练。系统实现了完整的评估指标体系,包括准确率、精确率、召回率、特异度和F1分数等6项指标,并通过动态曲线可视化模块实时监控训练过程。采用早停机制保存最佳模型,验证集准确率提升可达3.2%。 工程实现亮点 1. 模块化设计:分离数据加载、模型构建和训练流程,支持快速迭代 2. 自动化评估:每轮训练自动生成指标报告和可视化曲线 3. 设备自适应:智能检测CUDA可用性,无缝切换训练设备 4. 中文支持:优化可视化界面的中文显示与负号渲染 实验表明,该系统在224×224分辨率图像分类任务中,仅需2个epoch即可达到92%以上的验证准确率。ASPP模块的引入使小目标识别准确率提升15%,特别适用于医疗影像等需要细粒度分类的场景。未来可通过轻量化改造进一步优化推理速度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值