Testing Round #12 A,B,C 讨论,贪心,树状数组优化dp
题目链接:http://codeforces.com/contest/597
1 second
256 megabytes
standard input
standard output
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.
The only line contains three space-separated integers k, a and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).
Print the required number.
- 1 1 10
- 10
- 2 -4 4
- 5
题意:找出[a,b]区间内整除k的数的个数;
思路:小心点特判即可;
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- #include<string>
- #include<queue>
- #include<algorithm>
- #include<stack>
- #include<cstring>
- #include<vector>
- #include<list>
- #include<set>
- #include<map>
- using namespace std;
- #define ll long long
- #define pi (4*atan(1.0))
- #define eps 1e-14
- #define bug(x) cout<<"bug"<<x<<endl;
- const int N=1e5+,M=4e6+,inf=;
- const ll INF=1e18+,mod=1e9+;
- /// 数组大小
- int main()
- {
- ll k,a,b;
- scanf("%lld%lld%lld",&k,&a,&b);
- if(a<=&&b>=)
- printf("%lld\n",(b/k)-(a/k)+);
- else if(a>=&&b>=)
- printf("%lld\n",(b/k)-(a/k+(a%k?:))+);
- else
- printf("%lld\n",(abs(a)/k)-(abs(b)/k+(abs(b)%k?:))+);
- return ;
- }
4 seconds
256 megabytes
standard input
standard output
A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order is characterized by two time values — the start time li and the finish time ri (li ≤ ri).
Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept?
No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both.
The first line contains integer number n (1 ≤ n ≤ 5·105) — number of orders. The following n lines contain integer values li and ri each (1 ≤ li ≤ ri ≤ 109).
Print the maximal number of orders that can be accepted.
- 2
7 11
4 7
- 1
- 5
1 2
2 3
3 4
4 5
5 6
- 3
- 6
4 8
1 5
4 7
2 5
1 3
6 8
- 2
贪心:按r从小到大排序即可;
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- #include<string>
- #include<queue>
- #include<algorithm>
- #include<stack>
- #include<cstring>
- #include<vector>
- #include<list>
- #include<set>
- #include<map>
- using namespace std;
- #define ll long long
- #define pi (4*atan(1.0))
- #define eps 1e-14
- #define bug(x) cout<<"bug"<<x<<endl;
- const int N=5e5+,M=4e6+,inf=;
- const ll INF=1e18+,mod=1e9+;
- struct is
- {
- int l,r;
- bool operator <(const is &c)const
- {
- return r<c.r;
- }
- }a[N];
- /// 数组大小
- int main()
- {
- int n;
- scanf("%d",&n);
- for(int i=;i<=n;i++)
- scanf("%d%d",&a[i].l,&a[i].r);
- sort(a+,a++n);
- int s=,ans=;
- for(int i=;i<=n;i++)
- {
- if(a[i].l>s)
- {
- ans++;
- s=a[i].r;
- }
- }
- printf("%d\n",ans);
- return ;
- }
1 second
256 megabytes
standard input
standard output
For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.
First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) — the length of sequence and the number of elements in increasing subsequences.
Next n lines contains one integer ai (1 ≤ ai ≤ n) each — elements of sequence. All values ai are different.
Print one integer — the answer to the problem.
- 5 2
1
2
3
5
4
- 7
题意:给你n个数,最长上升子序列长度为k+1的个数;
思路:看下数据范围k<10很关键,dp[i][j]表示以i为结束长度为j时候的方案数
现在你到i的时候你只需要再T[j](树状数组)的a[i]的位置表示方案数;
统计小于a[i]的方案,k==0时候特判;
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- #include<string>
- #include<queue>
- #include<algorithm>
- #include<stack>
- #include<cstring>
- #include<vector>
- #include<list>
- #include<set>
- #include<map>
- using namespace std;
- #define ll long long
- #define pi (4*atan(1.0))
- #define eps 1e-14
- #define bug(x) cout<<"bug"<<x<<endl;
- const int N=1e5+,M=4e6+,inf=;
- const ll INF=1e18+,mod=1e9+;
- struct AYT
- {
- ll tree[N];
- int lowbit(int x)
- {
- return x&-x;
- }
- void update(int x,ll c)
- {
- while(x<N)
- {
- tree[x]+=c;
- x+=lowbit(x);
- }
- }
- ll query(int x)
- {
- ll ans=;
- while(x)
- {
- ans+=tree[x];
- x-=lowbit(x);
- }
- return ans;
- }
- };
- AYT T[];
- /// 数组大小
- int a[N];
- int main()
- {
- int n,k;
- scanf("%d%d",&n,&k);
- for(int i=;i<=n;i++)
- scanf("%d",&a[i]);
- if(k==)
- return *printf("%d\n",n);
- ll ans=;
- for(int i=;i<=n;i++)
- {
- ans+=T[k].query(a[i]-);
- for(int j=k;j>=;j--)
- {
- ll x=T[j-].query(a[i]-);
- T[j].update(a[i],x);
- }
- T[].update(a[i],);
- }
- printf("%lld\n",ans);
- return ;
- }
1 second
256 megabytes
standard input
standard output
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.
The only line contains three space-separated integers k, a and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).
Print the required number.
- 1 1 10
- 10
- 2 -4 4
- 5
Testing Round #12 A,B,C 讨论,贪心,树状数组优化dp的更多相关文章
- Codeforces Beta Round #12 (Div 2 Only) D. Ball 树状数组查询后缀、最值
http://codeforces.com/problemset/problem/12/D 这里的BIT查询,指的是查询[1, R]或者[R, maxn]之间的最值,这样就够用了. 设三个权值分别是b ...
- Codeforces Round #333 (Div. 1) C. Kleofáš and the n-thlon 树状数组优化dp
C. Kleofáš and the n-thlon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
- 【bzoj4240】有趣的家庭菜园 贪心+树状数组
题目描述 对家庭菜园有兴趣的JOI君每年在自家的田地中种植一种叫做IOI草的植物.JOI君的田地沿东西方向被划分为N个区域,由西到东标号为1~N.IOI草一共有N株,每个区域种植着一株.在第i个区域种 ...
- 贪心+树状数组维护一下 Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) D
http://codeforces.com/contest/724/problem/D 题目大意:给你一个串,从串中挑选字符,挑选是有条件的,按照这个条件所挑选出来的字符集合sort一定是最后选择当中 ...
- [JZO6401]:Time(贪心+树状数组)
题目描述 小$A$现在有一个长度为$n$的序列$\{x_i\}$,但是小$A$认为这个序列不够优美. 小$A$认为一个序列是优美的,当且仅当存在$k\in [1,n]$,满足:$$x_1\leqsla ...
- D 洛谷 P3602 Koishi Loves Segments [贪心 树状数组+堆]
题目描述 Koishi喜欢线段. 她的条线段都能表示成数轴上的某个闭区间.Koishi喜欢在把所有线段都放在数轴上,然后数出某些点被多少线段覆盖了. Flandre看她和线段玩得很起开心,就抛给她一个 ...
- [BZOJ4240]有趣的家庭菜园(贪心+树状数组)
最后数列一定是单峰的,问题就是最小化最后的位置序列的逆序对数. 从大到小加数,每次贪心看放左边和右边哪个产生的逆序对数更少,树状数组即可. 由于大数放哪对小数不产生影响,所以正确性显然. 注意相同数之 ...
- [P4064][JXOI2017]加法(贪心+树状数组+堆)
题目描述 可怜有一个长度为 n 的正整数序列 A,但是她觉得 A 中的数字太小了,这让她很不开心. 于是她选择了 m 个区间 [li, ri] 和两个正整数 a, k.她打算从这 m 个区间里选出恰好 ...
- [luoguP2672] 推销员(贪心 + 树状数组 + 优先队列)
传送门 贪心...蒟蒻证明不会... 每一次找最大的即可,找出一次最大的,数列会分为左右两边,左边用stl优先队列维护,右边用树状数组维护.. (线段树超时了....) 代码 #include < ...
随机推荐
- [LintCode] 394. Coins in a Line_ Medium tag:Dynamic Programming_博弈
Description There are n coins in a line. Two players take turns to take one or two coins from right ...
- Winsock网络编程
Winsock是Windows下网络编程的标准接口.使用Winsock编程的步骤一般是比较固定的. 首先要包含头文件#include <WinSock2.h>,同时要添加WS2_32.li ...
- jmeter 读取excel数据
jmeter 读取excel数据使用的方法是使用Jmeter CSV Data Set Config参数化 但是将excel文件保存成csv格式后,jmeter读取后返回的数据总是出现乱码问题, 以下 ...
- Listener—监听器
什么是监听器? 监听器是Web应用程序事件模型的一部分 监听器的作用? 1:Web应用中某些状态发生改变的时候会产生相应的事件: a)servletContext.HttpSession.Servle ...
- hexo修改Next主题的样式
Next主题默认对超链接只有下划线样式,很容易被忽略,就想着怎么修改下 主题样式是在\hexoBlog\themes\next\source\css,这里面保存了Muse,Mist和Pisces三个主 ...
- 岭回归(Ridge Regression)
一.一般线性回归遇到的问题 在处理复杂的数据的回归问题时,普通的线性回归会遇到一些问题,主要表现在: 预测精度:这里要处理好这样一对为题,即样本的数量和特征的数量 时,最小二乘回归会有较小的方差 时, ...
- OS X 下动态库的引用
foo.c #include <stdio.h> void foo(void) { printf("foo.\n"); } main.c #include <st ...
- JSF Web框架与Facelets表现层技术
JSF(JavaServer Faces) JSF应用程序的生命周期从客户端对页面发出HTTP请求时开始,并在服务器响应页面时结束.JSF生命周期分为运行阶段和渲染阶段两个主要阶段. 执行阶段 当第一 ...
- ThinkPHP CURD mysql操作
ThinkPHP CURD操作 ThinkPHP提供了灵活和方便的数据操作方法,对数据库操作的四个基本操作(CURD):创建.更新.读取和删除的实现是最基本的,也是必须掌握的,在这基础之上才能熟悉更多 ...
- Js基础知识6-JavaScript匿名函数和闭包
匿名函数 1,把匿名函数赋值给变量 var test = function() { return 'guoyu'; }; alert(test);//test是个函数 alert(test()); 2 ...