B. Lord of the Values 思维数学建构 附加 英文翻译
原题链接 Problem - 1523B - Codeforces
题目及部分翻译
While trading on(贸易,利用) his favorite exchange trader William realized that he found a vulnerability( [ˌvʌlnərəˈbɪləti] n.易损性;弱点). Using this vulnerability he could change the values of certain internal variables(内部变量) to his advantage. To play around he decided to change the values of all internal variables from a1,a2,…,an to −a1,−a2,…,−an. For some unknown reason, the number of service variables is always an even number.
当和他最喜欢的交易员交易时, 威廉意识到他发现了一个弱点。使用这个弱点,他可以改变确定的内部变量成他的优势。他决定改变所有内部变量的值,从正改为负。因不明原因,服务变量的数目总是偶数。
William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5000 and after every operation no variable can have an absolute value greater than 1018. William can perform actions of two types for two chosen variables with indices i and j, where i<j:
威廉知道,他的行为会吸引交易所安全团队越来越多的注意,所以他的操作数不能超过5000,并且每次操作完,没有变量的绝对值会超过10的18次方。威廉展示2种操作,其中的变量是i,j,满足i<j;
- Perform assignment ai=ai+aj
- Perform assignment aj=aj−ai
类型一:ai=ai+aj
类型二:aj=aj−ai
William wants you to develop a strategy that will get all the internal variables to the desired values.
Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤20). Description of the test cases follows.
The first line of each test case contains a single even integer nn (2≤n≤103), which is the number of internal variables.
The second line of each test case contains nn integers a1,a2,…,an (1≤ai≤109), which are initial values of internal variables.
For each test case print the answer in the following format:
The first line of output must contain the total number of actions kk, which the strategy will perform. Note that you do not have to minimize kk. The inequality k≤5000k≤5000 must be satisfied.
Each of the next kk lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i<j should hold.
We can show that an answer always exists.
解析: 对于任意两个元素,只需6步,可以使二者都变为负值
ai aj
ai+aj aj
ai+2aj aj
ai+2aj -ai-aj
aj -ai-aj
-ai -ai-aj
-ai -aj
代码
#include <iostream> using namespace std; const int N = 1e3+10; int a[N]; int main()
{
int t;
cin >> t;
while(t --)
{
int n;
cin >> n;
for(int i = 0; i < n; i ++)
cin >> a[i]; cout << n * 3 << endl;
for(int i = 1; i < n; i += 2)
{
int j = i;
cout << "1 " << j <<' ' << j+1 << endl;
cout << "1 " << j <<' ' << j+1 << endl;
cout << "2 " << j <<' ' << j+1 << endl;
cout << "1 " << j <<' ' << j+1 << endl;
cout << "1 " << j <<' ' << j+1 << endl;
cout << "2 " << j <<' ' << j+1 << endl; }
}
return 0;
}
B. Lord of the Values 思维数学建构 附加 英文翻译的更多相关文章
- [Codeforces 1178D]Prime Graph (思维+数学)
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...
- 牛客网多校第9场 E Music Game 【思维+数学期望】
题目:戳这里 题意:鼠标点击n下,第i次点击成功的概率为p[i],连续点击成功x次可以获得x^m分,求n次点击总分数的数学期望. 解题思路:数学期望的题很多都需要转化思维,求某一个单独状态对整体答案的 ...
- Codeforces Round #304 (Div. 2) D 思维/数学/质因子/打表/前缀和/记忆化
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- 牛客网多校第5场 F take 【思维+数学期望】
题目:戳这里 思路来源:视频讲解 题意:有n个箱子按1...n标号,每个箱子有大小为di的钻石概率为pi,我们初始有个大小为0的钻石,从1到n按顺序打开箱子,遇到比手中大的箱子就换,求交换次数的数学期 ...
- Codeforces Round #272 (Div. 2) D. Dreamoon and Sets (思维 数学 规律)
题目链接 题意: 1-m中,四个数凑成一组,满足任意2个数的gcd=k,求一个最小的m使得凑成n组解.并输出 分析: 直接粘一下两个很有意思的分析.. 分析1: 那我们就弄成每组数字都互质,然后全体乘 ...
- 2017多校第一套&&hdu6038 思维 数学
链接 http://acm.hdu.edu.cn/showproblem.php?pid=6038 题意: 给你一个a序列,代表0到n-1的排列:一个b序列代表0到m-1的排列.问你可以找出多少种函 ...
- [codeforces Mail.Ru Cup 2018 Round 3][B Divide Candies ][思维+数学]
https://codeforces.com/contest/1056/problem/B 题意:输入n,m 求((a*a)+(b*b))%m==0的(a,b)种数(1<=a,b<= ...
- 51Nod 1305 Pairwise Sum and Divide | 思维 数学
Output 输出fun(A)的计算结果. Input示例 3 1 4 1 Output示例 4 first try: #include "bits/stdc++.h" using ...
- 茅台【思维/数学/剪枝】By cellur925
题目传送门 给你\(n\)根木棍,问有多少种方法,使得选出的三根木棍能组成三角形. 开始想要用搜索的,但是写着写着卡壳了(?),于是改用贪心,开始对拍,觉得很稳,只是最后两个数据可能有点卡.很第一题难 ...
随机推荐
- CodeTON Round 1 (Div. 1 + Div. 2, Rated, Prizes!) A ~ D
A. 给定一个序列,对于任意1<=k<=n 都满足|ai−ak|+|ak−aj|=|ai−aj|, 找满足条件的i和j并输出 思路: 观察样例,发现输出的是最大值和最小值,那么猜答案是最大 ...
- 女朋友汇总表格弄了大半天,我实在看不下去了,用40行代码解决问题 | Python使用openpyxl库读写表格Excel(xlsx)
1.openpyxl基本操作 python程序从excel文件中读数据基本遵循以下步骤: 1.import openpyxl 2.调用openpyxl模块下的load_workbook('你的文件名. ...
- bzoj5315/luoguP4517 [JSOI2018]防御网络(仙人掌,dp)
bzoj5315/luoguP4517 防御网络(仙人掌,dp) bzoj Luogu 题目描述略(太长了) 题解时间 本题和斯坦纳树无关. 题面保证了是一个仙人掌...? 但这个环之间甚至交点都没有 ...
- 『现学现忘』Docker基础 — 35、实战:自定义CentOS镜像
目录 1.前提说明 2.编写Dockerfile文件 3.构建镜像 4.运行镜像 5.列出镜像的变更历史 1)目标:自定义镜像wokong_centos. 2)所用到的保留字指令: FROM:基础镜像 ...
- GC是什么? 为什么要有GC?
GC是垃圾收集的意思(Gabage Collection),内存处理是编程人员容易出现问题的地方,忘记或者错误的内存回收会导致程序或系统的不稳定甚至崩溃,Java提供的GC功能可以自动监测对象是否超过 ...
- Dubbo 的整体架构设计有哪些分层?
接口服务层(Service):该层与业务逻辑相关,根据 provider 和 consumer 的 业务设计对应的接口和实现 配置层(Config):对外配置接口,以 ServiceConfig 和 ...
- 什么是 Swagger?你用 Spring Boot 实现了它吗?
Swagger 广泛用于可视化 API,使用 Swagger UI 为前端开发人员提供在线沙箱.Swagger 是用于生成 RESTful Web 服务的可视化表示的工具,规范和完整框架实现.它使文档 ...
- Error running 'App': Command line is too long. Shorten command line for App or also for Spring Boot default configuration.
找到标签 <component name="PropertiesComponent">.在标签里加一行 : <property name="dynam ...
- Oracle入门基础(四)一一多行函数
SQL> --工资总额 SQL> select sum(sal) from emp; SUM(SAL) 29025 SQL> --人数 SQL> select count(*) ...
- 为什么使用 Executor 框架?
每次执行任务创建线程 new Thread()比较消耗性能,创建一个线程是比较耗时. 耗资源的. 调用 new Thread()创建的线程缺乏管理,被称为野线程,而且可以无限制的创建, 线程之间的相互 ...