赞
踩
很明显第二个式子满足题目条件
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define cy cout << "YES" << endl
- #define cn cout << "NO" << endl
- #define forn(i, l, r) for (int i = l; i <= r; i++)
- #define fornk(i, l, r, k) for (int i = l; i <= r; i += k)
- const int N = 2e5 + 5;
- ll T;
- ll n;
- ll a[N];
- void solve() {
- cin >> n;
- forn(i, 1, n) cout << 2 * i << ' ';
- cout << endl;
- }
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- T = 1;
- cin >> T;
- while (T--) solve();
- return 0;
- }
就是离正确位置的距离,题目让我们求使用最大的移动步数移动全部到正确的位置,那么这个最大移动距离的既是所有的最大公约数
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define cy cout << "YES" << endl
- #define cn cout << "NO" << endl
- #define forn(i, l, r) for (int i = l; i <= r; i++)
- #define fornk(i, l, r, k) for (int i = l; i <= r; i += k)
- const int N = 2e5 + 5;
- ll T;
- ll n;
- ll a[N];
- ll ans;
- void solve() {
- ans = 0;
- cin >> n;
- forn(i, 1, n) cin >> a[i];
- forn(i, 1, n) ans = __gcd( abs(a[i] - i), ans);
- cout << ans << endl;
- }
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- T = 1;
- cin >> T;
- while (T--) solve();
- return 0;
- }
我们定义数组c为a数组中严格大于的个数,那么从从第一个数开始我们有个数可以选,接下来是选,...那么答案既是 ,注意对小于1的情况特判
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define cy cout << "YES" << endl
- #define cn cout << "NO" << endl
- #define forn(i, l, r) for (int i = l; i <= r; i++)
- #define fornk(i, l, r, k) for (int i = l; i <= r; i += k)
- #define forn_(i, l, r) for (int i = l; i >= r; i--)
- #define fornk_(i, l, r, k) for (int i = l; i >= r; i -= k)
- const int N = 2e5 + 5;
- ll T;
- ll n;
- ll a[N], b[N], c[N];
- ll ans;
- ll mod = 1e9 + 7;
- bool cmp(ll a, ll b) {
- return a > b;
- }
- void solve() {
- ans = 1;
- cin >> n;
- forn(i, 1, n) cin >> a[i];
- forn(i, 1, n) cin >> b[i];
- sort(a + 1, a + n + 1, cmp);
- sort(b + 1, b + 1 + n);
- ll cnt = n;
- forn(i, 1, n) {
- while (a[cnt] <= b[i]) cnt--;
- c[i] = cnt;
- }
- cnt = 0;
- forn_(i, n, 1) {
- if (c[i] - cnt < 1) ans = 0;
- ans *= (c[i] - cnt++);
- ans %= mod;
- }
- cout << ans << endl;
- }
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- T = 1;
- cin >> T;
- while (T--) solve();
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。