首页 > 其他分享 >C1. Dual (Easy Version)

C1. Dual (Easy Version)

时间:2023-08-08 17:22:31浏览次数:36  
标签:int ne Version Easy C1 include po

link
像这种构造题可以先分类讨论一波
比如说全是正数或者全是负数,那么显然的就是可以用前缀和和后缀和来解决。
而如果有正有负呢?可以注意到的是数字非常小,而\(2^5=32>20\)了,那么我们就可以先随便找到一个正数,把他自加上5次,然后第二个数加上它2次
之后的数加上前面的数两次,这样结果一定是递加的。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<bitset>
using namespace std;
int t;
int n;
int a[30];
int po;
int ne;
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		po=ne=0;
		for(int i=1;i<=n;++i){
			scanf("%d",&a[i]);
			if(a[i]>0) po=i;
			if(a[i]<0) ne=i;
		}
		if(po==0&&ne==0){
			cout<<0<<endl;
			continue;
		}
		if(po==0){
			cout<<n-1<<endl;
			for(int i=n;i>1;--i){
				cout<<i-1<<" "<<i<<endl;
			}
			continue;
		}
		if(ne==0){
			cout<<n-1<<endl;
			for(int i=1;i<n;++i){
				cout<<i+1<<" "<<i<<endl;
			}
			continue;
		}
		cout<<(n-1)*2+5<<endl;
		for(int i=1;i<=5;++i){
			printf("%d %d\n",po,po);
		}
		printf("2 %d\n2 %d\n",po,po);
		for(int i=3;i<=n;++i){
			printf("%d %d\n%d %d\n",i,i-1,i,i-1);
		}
	}
	return 0;
}

标签:int,ne,Version,Easy,C1,include,po
From: https://www.cnblogs.com/For-Miku/p/17614924.html

相关文章

  • STC15 外部中断编程笔记
    以STC15W4K58S4为例,可以将片上的外部中断资源分为“高级”和“低级”两类,EXINT0和EXINT1属于高级的,EXINT2~EXINT4属于低级的。“高级”的外部中断可以配置中断优先级,选择中断源;低级的则不行。EXINT0和EXINT1的配置这两个外部中断的配置寄存器都可位寻址,因此可以直......
  • ASP.NET+EASYUI 换肤代码
    ​​编辑​......
  • 遇到的问题----java Unsupported major.minor version 51.0
     Unsupportedmajor.minorversion51.0不同的JDK版本使用的major.minor不同,所以会导致这个错误。编译器运行的jdk选择版本和使用的jdk版本号应该对应。解决起来也很方便:打开exclipse中项目上的属性—javacompiler–选择一个合适的版本后重新编译即可。具体步骤解决:项目------......
  • 解决ls: relocation error: /lib64/libacl.so.1: symbol getxattr, version ATTR_1.0
    这个问题是在我conda装了一个包之后就出现了,ls等最基础的命令没有办法用了,网上的帖子也没有很好解决我的问题,而且我试了把我刚刚安的包删掉也没有解决,后面仔细分析一下这个报错,猜测应该是包安装的过程中本地conda中的一些依赖与系统中的一些起了冲突。通过ldd/lib64/libacl.so......
  • How to update to the latest Python version On Linux All In One
    HowtoupdatetothelatestPythonversionOnLinuxAllInOneupdatetothelatestPythonversiononRaspberryPierrorsold$python--versionPython3.9.2new$sudoaptupdate$aptlist|greppython3.10WARNING:aptdoesnothaveastableCL......
  • E1. PermuTree (easy version)
    E1.PermuTree(easyversion)Thisistheeasyversionoftheproblem.Thedifferencesbetweenthetwoversionsaretheconstrainton$n$andthetimelimit.Youcanmakehacksonlyifbothversionsoftheproblemaresolved.Youaregivenatreewith$n$......
  • FindByNameAsync vs FindByIdAsync vs FindByEmailAsync vs FindByLoginAsync
    InASP.NETIdentity,UserManagerisacoreclassthatprovidesasetofAPIstomanageuseraccounts.Themethodsyoumentioned(FindByNameAsync,FindByIdAsync,FindByEmailAsync,andFindByLoginAsync)areusedtofindauserbasedondifferentcriteria.T......
  • 取数游戏 Atcoder-abc128_d
    枚举两端取了几个数,将手中的负数从小到大放回序列即可#include<bits/stdc++.h>usingnamespacestd;intn,m,a[55],c[55],ans=-0x7fffffff;intmain(){scanf("%d%d",&n,&m);for(inti=1;i<=n;i++)scanf("%d",&a[i]);f......
  • 使用EasyX为线性筛创造动画
    更好的阅读体验:http://t.csdn.cn/pvMNR代码如下:#include<iostream>#include<string>#include<graphics.h>usingnamespacestd;#defineBLOCK_WIDTH70#defineSTART_X80#defineSTART_Y60#defineMAX_PER_LINE10#defineTEXT_COLOR_UNCHOOSE......
  • /lib64/libstdc++.so.6: version `GLIBCXX_3.4.26' not found
    原因使用的gcc没有找到对应的glib库。每个版本的glib都会有改变,所以使用的时候必须匹配。大部分是因为自己编译升级了gcc,再用新的gcc编译程序时没有找到当时匹配的类库。查找原因报错提示很明确了,/lib64/libstdc++.so.6中没有找到GLIBCXX_3.4.26版本内容。正常情况/lib64/lib......