cf1523B. Lord of the Values
生活随笔
收集整理的這篇文章主要介紹了
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 #elsestartTime= clock();freopen("in.txt", "r", stdin); #endif } void Time_test() { #ifdef ONLINE_JUDGE #elseendTime= 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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 牙与大脑的神经有关吗?
- 下一篇: 吞咽口水左侧太阳穴疼是为什么?