日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Odd Grasshopper 奇偶找规律

發(fā)布時(shí)間:2025/3/19 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Odd Grasshopper 奇偶找规律 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.


思路 :

  • 首先根據(jù)輸入的奇偶性分別找規(guī)律,發(fā)現(xiàn)與輸入無關(guān),都滿足4個(gè)一循環(huán)的規(guī)律
  • 如果次數(shù)n剛好是4的倍數(shù),那么就是x0,否則,找到小于n中最靠近n的一個(gè)4的倍數(shù),從它開始模擬到n,就是答案
#include <iostream> #include <algorithm> #include <math.h>using namespace std;typedef long long ll;ll td(ll start, ll end, ll ans) {for (ll i = start + 1; i <= end; i ++ ){if (ans % 2 == 0) ans = ans - i;else ans = ans + i;}return ans; }int main() {ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);int _;cin >> _;while (_ -- ){ll x0, n;cin >> x0 >> n;if (n % 4 == 0){cout << x0 << endl;continue;}ll bc = 0;for (ll i = n - 1; ; i -- )if (i % 4 == 0){bc = i;break;}cout << td(bc, n, x0) << endl;}return 0; }

總結(jié)

以上是生活随笔為你收集整理的Odd Grasshopper 奇偶找规律的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。