• CF1523B Lord of the Values(构造+思维)


    传送门

    题意:

    给定一个长度为(n(2<=n<=10^{3}且为偶数))的序列,每次都可以选择两个下标(i,j)并且(i<j),进行下面两种操作之一:
    (1.) (a_{i}=a_{i}+a_{j})
    (2.a_{j}=a_{j}-a_{i})
    最多执行(5000)次操作,并且操作后的的值不能超过(10^{18})
    输出方案使得序列全部变为相反数。

    思路:

    对于两个数来说,按照 (1 2 1 1 2 1)的顺序执行能够将这两个数都变为自身的相反数。所以,两两的进行操作,最多操作次数为(6*n/2=3*n)次。

    代码:

    // Problem: B. Lord of the Values
    // Contest: Codeforces - Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)
    // URL: https://codeforces.com/contest/1523/problem/B
    // Memory Limit: 256 MB
    // Time Limit: 1000 ms
    // 
    // Powered by CP Editor (https://cpeditor.org)
    
    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=1100;
    int n,a[maxn];
    int main(){
    	int T;cin>>T;
    	while(T--){
    		cin>>n;
    		for(int i=1;i<=n;i++) cin>>a[i];
    		cout<<3*n<<endl;
    		for(int i=1;i<=n;i+=2){
    			cout<<"1 "<<i<<" "<<i+1<<endl;
    			cout<<"2 "<<i<<" "<<i+1<<endl;
    			cout<<"1 "<<i<<" "<<i+1<<endl;
    			cout<<"1 "<<i<<" "<<i+1<<endl;
    			cout<<"2 "<<i<<" "<<i+1<<endl;
    			cout<<"1 "<<i<<" "<<i+1<<endl;
    		}
    	}
    	return 0;
    }
    
    
    
  • 相关阅读:
    第一周学习总结
    lhgdialog窗口插件
    validate验证
    jxl自己写的例子
    jxl导入/导出excel
    struts2文件上传
    struts2基于注解的文件下载
    学校操场的印象
    我的开源项目:JPEG分析器
    我的开源项目:TS封装格式分析器
  • 原文地址:https://www.cnblogs.com/OvOq/p/14843350.html
Copyright © 2020-2023  润新知