Testing Round #12 597ABC题解
来源:互联网 发布:无烟艾条 知乎 编辑:程序博客网 时间:2024/06/05 05:57
题目链接: 点击打开链接
A: 给出k, a, b. 问你在[a, b]区间内有多少可以整除k的数.
脑洞题目, 计算此区间长度可以存放k的个数即可.
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"using namespace std;typedef long long ll;ll a, b, k;int main(int argc, char const *argv[]){ scanf("%lld%lld%lld", &k, &a, &b); if(b <= 0) { a = -a; b = -b; swap(a, b); } a--; ll ans = b / k - a / k; if(a < 0 && a % k) ans++; printf("%lld\n", ans); return 0;}
B: 给出n个订单的起始时间和结束时间, 问你最多可以接多少个订单, 注意同一时间点不可存在两订单.
贪心题, 按照结束时间排序, 如果开始时间在当前结束时间之后则ans++.
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"#include "utility"using namespace std;const int MAXN = 5e5 + 5;int n, x, y, ans;pair<int, int> p[MAXN];int main(int argc, char const *argv[]){ scanf("%d", &n); for(int i = 0; i < n; ++i) { scanf("%d%d", &x, &y); p[i] = make_pair(y, x); } sort(p, p + n); x = p[0].second, y = 0; for(int i = 0; i < n; ++i) if(p[i].second > y) { x = p[i].second; y = p[i].first; ans++; } printf("%d\n", ans); return 0;}
C: 给出n个数, 问你上升子序列长度为k + 1的有多少个.
树状数组题目, query(x, y)返回长度为x, 子序列长度为y的上升子序列个数.
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"using namespace std;const int MAXN = 1e5 + 5;typedef long long ll;int n, k;ll a[12][MAXN];void update(int i, int j, ll v){ while(i <= n + 1) { a[j][i] += v; i += i & (-i); }}ll query(int i, int j){ if(i == 0) return 0; return a[j][i] + query(i - (i & -i), j);}int main(int argc, char const *argv[]){ scanf("%d%d", &n, &k); update(1, 0, 1); for(int i = 0; i < n; ++i) { int x; scanf("%d", &x); x++; for(int j = k + 1; j > 0; --j) update(x, j, query(x, j - 1)); } printf("%lld\n", query(n + 1, k + 1)); return 0;}
1 0
- Testing Round #12 597ABC题解
- [Codeforces Round #309 (Div. 2)] #ABC题解
- [Codeforces Round #310 (Div. 2)] #ABC题解
- Codeforces Round #312 (Div. 2) ABC题解
- Codeforces Round #331 (Div. 2) (ABC题解)
- Codeforces Round #418 (Div. 2) 题解 ABC
- Codeforces 597 A. Divisibility 【Testing Round #12】
- 【Codeforces】Testing Round #12
- Testing Round #12
- Testing Round #12
- Codeforces Round #259 (Div. 2) ABC简要题解
- Codeforces Round #323 (Div. 2) ABC题解(全是暴力)
- Codeforces Round #325 (Div. 2) 586ABC题解
- Codeforces Round #326 (Div. 2) 588ABC题解
- Codeforces Round #327 (Div. 2) 591ABC题解
- Codeforces Round #328 (Div. 2) 592ABC题解
- Codeforces Round #331 (Div. 2) 596ABC题解
- “玲珑杯”ACM比赛 Round #18 ABC题解
- 苹果开发 笔记(93) UITableView 的编辑模式
- 传统Web应用请求和响应特点
- AJAX【Asynchronous异步的JS和XML】,工作原理与特点
- 黑马程序员_NSString
- C#之VS自带RDLC报表学习
- Testing Round #12 597ABC题解
- Web Service 教程
- WinPcap笔记(8):分析数据包(2)
- Redis中的排序
- C++Builder实现鼠标钩子
- CodeForces CF 360E Levko and Game 贪心+SPFA
- Python3.5安装numpy,SciPy后,出现ImportError
- max-min fairness 最大最小公平算法
- B. Rebranding