cf1523B. Lord of the Values

Posted Jozky86

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cf1523B. Lord of the Values相关的知识,希望对你有一定的参考价值。

cf1523B. Lord of the Values

题意:

给你一个数组,有n个数,n为偶数,a1,a2…an
现在有两个操作:
对于i<j
操作1:ai=ai+aj
操作2:aj=aj-ai
把原数组转换为-a1,-a2,-a3…

题解:

一开始没思路。。cf的b题应该不会很难。。
题目说了n是偶数个?说明什么?
我突然明白,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
// Data:2021-08-10 21:09:28
// By Jozky

#include <bits/stdc++.h>
#include <unordered_map>
#define debug(a, b) printf("%s = %d\\n", a, b);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
clock_t startTime, endTime;
//Fe~Jozky
const ll INF_ll= 1e18;
const int INF_int= 0x3f3f3f3f;
template <typename T> inline void read(T& x)
{
    T f= 1;
    x= 0;
    char ch= getchar();
    while (0 == isdigit(ch)) {
        if (ch == '-')
            f= -1;
        ch= getchar();
    }
    while (0 != isdigit(ch))
        x= (x << 1) + (x << 3) + ch - '0', ch= getchar();
    x*= f;
}
template <typename T> inline void write(T x)
{
    if (x < 0) {
        x= ~(x - 1);
        putchar('-');
    }
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
void rd_test()
{
#ifdef ONLINE_JUDGE
#else
    startTime= clock();
    freopen("in.txt", "r", stdin);
#endif
}
void Time_test()
{
#ifdef ONLINE_JUDGE
#else
    endTime= clock();
    printf("\\nRun Time:%lfs\\n", (double)(endTime - startTime) / CLOCKS_PER_SEC);
#endif
}
const int maxn= 3e4;
int a[maxn];
void solve(int a, int b)
{
    printf("1 %d %d\\n", a, b);
    printf("1 %d %d\\n", a, b);
    printf("2 %d %d\\n", a, b);
    printf("1 %d %d\\n", a, b);
    printf("1 %d %d\\n", a, b);
    printf("2 %d %d\\n", a, b);
}
int main()
{
    //rd_test();
    int t;
    read(t);
    while (t--) {
        int n;
        cin >> n;
        for (int i= 1; i <= n; i++)
            cin >> a[i];
        printf("%d\\n", n / 2 * 6);
        for (int i= 1; i <= n; i+= 2) {
            solve(i, i+1);
        }
    }
    return 0;
    //Time_test();
}

以上是关于cf1523B. Lord of the Values的主要内容,如果未能解决你的问题,请参考以下文章

B. Lord of the Values(思维)

cf1499D. The Number of Pairs

CF 1215 B The Number of Products(思维题)

CF1523H Hopping Around the Array

cf1523A. Game of Life

[CF1523H]Hopping Around the Array