• 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;

    1. Perform assignment ai=ai+aj
    2. Perform assignment aj=ajai

      类型一:ai=ai+aj

      类型二:aj=ajai

    William wants you to develop a strategy that will get all the internal variables to the desired values.
    威廉想要你去研究一种策略使得所有内部变量是他想要的值。
     
    Input

    Each test contains multiple test cases. The first line contains the number of test cases tt (1t20). Description of the test cases follows.

    The first line of each test case contains a single even integer nn (2n103), which is the number of internal variables.

    The second line of each test case contains nn integers a1,a2,,an (1ai109), which are initial values of internal variables.

    Output

    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 k5000k≤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;
    }
  • 相关阅读:
    EasyUi datagrid列表增加复选框
    List集合流处理类型小结
    MockMvc模拟对controller进行单元测试
    项目配置不带项目名称访问
    mongodb常用的sql语句总结
    git push时报错:Updates were rejected because the tip of your current branch is behind
    xml转json和实体类的两种方式
    win 10 关闭或打开 测试模式
    Wise Force Deleter 强制删除文件工具 ---- 亲测好用
    Win 10 你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问....
  • 原文地址:https://www.cnblogs.com/la-la-wanf/p/14882661.html
Copyright © 2020-2023  润新知