A: (读了10分钟题,真的菜 ,,,)
给出书中每一章的页数范围,最后给出当前所读到的页数。问未读完的章节数
直接判断就可以
#include <bits/stdc++.h>
#include <time.h>
#define fi first
#define se secondusing namespace std;typedef long long ll;
typedef double db;
int xx[4] = {1,-1,0,0};
int yy[4] = {0,0,1,-1};
const double eps = 1e-9;
typedef pair<int,int> P;
const int maxn = 2e6 + 5000;
const ll mod = 1e9 + 7;
inline int sign(db a) { return a < -eps ? -1 : a > eps;}
//inline int cmp(db a,db b){ return sign(a - b);}
ll mul(ll a,ll b,ll c) { ll res = 1; while(b) { if(b & 1) res *= a,res %= c; a *= a,a %= c,b >>= 1; } return res;}
ll phi(ll x) { ll res = x; for(ll i = 2; i * i <= x; i++) { if(x % i == 0) res = res / i * (i - 1); while(x % i == 0) x /= i; } if(x > 1) res = res / x * (x - 1); return res;}
int fa[maxn];
int Find(int x) { if(x != fa[x]) return fa[x] = Find(fa[x]); return fa[x];}
ll c,n,k;
struct node{int l,r;}g[maxn];
int main() {ios::sync_with_stdio(false);while(cin >> n){for(int i = 1;i <= n;i++){cin >> g[i].l >> g[i].r;}cin >> k;ll ans= 0;for(int i = 1 ;i <= n;i++){if(g[i].r >= k) ans++;}cout << ans << endl;}cerr << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;return 0;
}
B. Nastya Is Playing Computer Games
B
一排井盖,井盖下面有硬币。你要拿所有硬币。然后呢一开始每个井盖上都有一个石头。井盖上没有石头的时候才可以打开井盖拿硬币。
现在你在第k个井盖上,你可以向左走1或者向右走1或者把一块石头扔到别的井盖上, .问拿所有硬币需要的最少时间
向左向右走、投石头、捡东西都会花费1的时间
考虑 4 2
0 1 0 0
首先2位置把石头扔给1,然后拿2的金币,再往1走,因为1上现在有两个石头,所以要扔两次,然后捡金币,然后再往3,4走 ,,,,
显然1往左边走更优一些,那就只用考虑3部分,捡东西,行走和投石头的时间,可以分开计算
显然石头要投n + 1次,捡东西n次,行走的不重复的可以看做n - 1,接着考虑重复的,min(k - 1,n - k)就是重复的 ,加起来即可
int main() {ll n,kios::sync_with_stdio(false);while(cin >> n >> k){ ll ans = min(k - 1,n - k) + n + n + 1 + n - 1;cout << ans << endl;}cerr << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;return 0;
}
C Nastya Is Transposing Matrices
矩阵a和b,每次a可以翻转一个子矩阵(可以进行很多次操作),问你能否在很多次操作后,使得a->b
考虑每次翻转一个2 * 2的矩阵,
1 2 1 3
3 4 2 4
相当于交换了斜线的部分,所以可以考虑所有的都用2 * 2的来替换,这样的话直接判断两个矩阵斜边相不相同就可以了
#include <bits/stdc++.h>
#include <time.h>
#define fi first
#define se secondusing namespace std;typedef long long ll;
typedef double db;
int xx[4] = {1,-1,0,0};
int yy[4] = {0,0,1,-1};
const double eps = 1e-9;
typedef pair<int,int> P;
const int maxn = 600;
const ll mod = 1e9 + 7;
ll c,n,k;
int a[maxn][maxn];
int b[maxn][maxn];
int m;
int main() {ios::sync_with_stdio(false);while(cin >> n >> m) {for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> a[i][j];for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> b[i][j];for(int i = 1;i <= m;i++){vector<int>v1,v2;for(int j = i,k = 1;j >= 1 && k <= n;j--,k++){v1.push_back(a[k][j]),v2.push_back(b[k][j]);}sort(v1.begin(),v1.end()),sort(v2.begin(),v2.end());if(v1 != v2){cout << "No" << endl;return 0;}}for(int i = 1;i <= n;i++){vector<int>v1,v2;for(int j = i,k = m;j <= n && k>= 1;j++,k--){v1.push_back(a[j][k]),v2.push_back(b[j][k]);}sort(v1.begin(),v1.end()),sort(v2.begin(),v2.end());if(v1 != v2){cout << "No" << endl;return 0;}}cout << "Yes" << endl;}cerr << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;return 0;
}
D:Nastya Is Buying Lunch
告诉你一个1到n的排列,然后m对数,表示first当且仅当在second前面一个位置的时候,这两个数可以交换,现在问你最后一个数最多可以往前面走多少的距离
首先记录与最后一个数连接的点,然后从右往左贪心,在判断能否到达每个点的时候,只要判断一下向后面的边大于等于需要的边就可以(注意减去计算过得点数)
#include <bits/stdc++.h>
#include <time.h>
#define fi first
#define se secondusing namespace std;typedef long long ll;
typedef double db;
int xx[4] = {1,-1,0,0};
int yy[4] = {0,0,1,-1};
const double eps = 1e-9;
typedef pair<int,int> P;
const int maxn = 2e6 + 200;
const ll mod = 1e9 + 7;
ll c,n,k;
ll a[maxn];
int vis[maxn];
int cnt[maxn];
int mm;
struct node {int a,b;
} g[maxn];
map<P,int>m;
int ans = 0;
int check(int d) {return n - d - ans <= cnt[a[d]];
}
vector<int>v;
bool cmp(int a,int b){return a > b;
}
int main() {ios::sync_with_stdio(false);while(cin>> n >> mm) {for(int i = 1; i <= n; i++)cin >> a[i],vis[a[i]] = i;for(int i = 1; i <= mm; i++) {cin >> g[i].a >> g[i].b;if(vis[g[i].a] < vis[g[i].b])cnt[g[i].a]++;if(g[i].b == a[n])v.push_back(vis[g[i].a]);}sort(v.begin(),v.end(),cmp);for(auto d:v) {ans += check(d);}cout << ans << endl; }cerr << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;return 0;
}