Codeforces 1894C

编程入门 行业动态 更新时间:2024-10-21 23:08:44

<a href=https://www.elefans.com/category/jswz/34/1770097.html style=Codeforces 1894C"/>

Codeforces 1894C

题目链接:

题意:

给定序列 a a a 有没有一个序列 b b b 能够根据固定点 a i = i a_i = i ai​=i 循环左移 i i i 次,问能否在 k k k 次之内序列 b b b 能够还原成序列 a a a 。

思路:

可以观察循环左移 i i i 次,那么移动后的 a i a_i ai​ 都变成 b n b_n bn​ ,因此可以逆向模拟 a l a s t a_{last} alast​ 能否回到第 n − i + 1 n-i+1 n−i+1 个操作后的序列 b b b 。可以发现当 a l a s t > n a_{last}>n alast​>n 是不满足题意输出 N o No No ,因为 a a l a s t = a l a s t = l a s t > n a_{a_{last}}=a_{last}=last>n aalast​​=alast​=last>n 。如果 k > n k>n k>n 那么可以发现每 n n n 次都是一次循环,所以只需 k = m i n ( k , n ) k=min(k,n) k=min(k,n)

代码:

#include <bits/stdc++.h>
#define endy {cout<<"Yes\n";}//return ;}❤
#define endn {cout<<"No\n";}//return ;}❤
#define endl '\n'
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<ll,ll> pii;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF_ = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
ll n, m, k, x, y, res = 0, sum = 0, ans = 0, ma = 0, mi = INF;
void solve()
{cin >> n >> k;vector<ll> a(n+1);for(int i = 1; i <= n; i ++) cin >> a[i];k = min(n, k);int last = n;while(k --) {if(a[last] > n){endn return;}last += (n - a[last]);last %= n;}endy
}
int main()
{ios::sync_with_stdio(0);cin.tie(0);// cout.tie(0);ll _;cin>>_;while(_--)solve();return 0;
}

更多推荐

Codeforces 1894C

本文发布于:2024-03-07 20:57:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1718890.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Codeforces

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!