cf1556A. A Variety of Operations
生活随笔
收集整理的這篇文章主要介紹了
cf1556A. A Variety of Operations
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
cf1556A. A Variety of Operations
題意:
有兩個數a,b一開始都是0,現在有三種操作:
問從a=0,b=0到a=c,b=d最少需要幾步?
題解:
k=(c+d)/2
我們可以先用第一種操作將0,0都加到k,k.然后一個減,一個加,實現到c,d,這樣需要兩步
如果c和d的差為奇數,則無法通過操作實現
代碼:
// Problem: A. A Variety of Operations // Contest: Codeforces - Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2) // URL: https://codeforces.com/contest/1556/problem/A // Memory Limit: 256 MB // Time Limit: 1000 ms // Data:2021-08-31 23:35:41 // 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; void read(){}; template <typename _Tp, typename... _Tps> void read(_Tp& x, _Tps&... Ar) {x= 0;char c= getchar();bool flag= 0;while (c < '0' || c > '9')flag|= (c == '-'), c= getchar();while (c >= '0' && c <= '9')x= (x << 3) + (x << 1) + (c ^ 48), c= getchar();if (flag)x= -x;read(Ar...); } 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 LOCALstartTime= clock();freopen("in.txt", "r", stdin); #endif } void Time_test() { #ifdef LOCALendTime= clock();printf("\nRun Time:%lfs\n", (double)(endTime - startTime) / CLOCKS_PER_SEC); #endif } int main() {//rd_test();int t;read(t);while (t--) {int c, d;read(c, d);if (c > d)swap(c, d);int w= d - c;if (d == 0 && c == 0)printf("0\n");else if (w == 0)printf("1\n");else {if (w % 2 == 1)printf("-1\n");elseprintf("2\n");}}return 0;//Time_test(); }總結
以上是生活随笔為你收集整理的cf1556A. A Variety of Operations的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 炒黑豆的功效与作用、禁忌和食用方法
- 下一篇: 姜汁红糖的功效与作用、禁忌和食用方法