At the big break Nastya came to the school dining room. There are nn pupils in the school, numbered from 11 to nn. Unfortunately, Nastya came pretty late, so that all pupils had already stood in the queue, i.e. Nastya took the last place in the queue…
思路: 1. 最终答案不超过能与Nastya“直接交换”的人数. 2. 对于排在j前面的i,如果i和i-j之间(包括j)的每个人都能“直接交换”,j才能前进一步. 实现: #include <bits/stdc++.h> using namespace std; ; int a[N], p[N], cnt[N]; vector<int> v[N]; int main() { int n, m; while (cin >> n >> m) { ; i <…
题目连接:Codeforces 437C The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const int MAX_N = 1000 + 10; int G[MAX_N][MAX_N]; struct…