Educational Codeforces Round 86 (Rated for Div. 2)c和d
C. Yet Another Counting Problem
思路:数学题,没有什么思路就暴力打表找规律,我们可以发现以lcm[a,b]为一个周期,这个周期内的特殊数的个数是确定的。那么我们就把[1,lcm]内的特殊数暴力找出来。dp[i]代表的是前i个数中有多少个特殊数。
对于输入的l和r,我们只需要看他们中分别有多少个lcm以及对lcm取余是多少,然后加起来就可以了。分别对l和r计算出这个数,然后再用前缀和思想
/*
最k大值最小 ---> 二分答案*/
#include <iostream>
#include <cstdio>
#include <stack>
#include <sstream>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <cmath>
#include <deque>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#define mid ((l + r) >> 1)
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define _for(i,a,b) for( int i = (a); i < (b); ++i)
#define _rep(i,a,b) for( int i = (a); i <= (b); ++i)
#define for_(i,a,b) for( int i = (a); i >= (b); -- i)
#define rep_(i,a,b) for( int i = (a); i > (b); -- i)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define hash Hash
#define all(x) x.begin(),x.end()
#define next Next
#define f first
#define s second
using namespace std;
const int N = 2e5 + 10;
const double eps = 1e-9;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
inline LL read() {LL s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;
}
LL sum[N << 1];
int main()
{IOS;string s;int T;cin >> T;while(T --){LL a, b, c;cin >> a >> b >> c;if(a > b) swap(a,b);LL lcm = a / __gcd(a,b) * b;_for(i,0,lcm){sum[i] = 0;if((i%a)%b!=(i%b)%a) sum[i] = 1;if(i)sum[i] += sum[i - 1];}while(c--){LL l, r;cin >> l >> r;if(r < b) cout << "0 ";else{l --;LL Le = l / lcm * sum[lcm - 1] + sum[l % lcm];LL Ri = r / lcm * sum[lcm - 1] + sum[r % lcm];cout << Ri - Le << " ";}}cout << endl;}return 0;
}
题意:
给出n个数,每个数权值不超过k,现在要从这些数中选出一些组成若干个序列,要求每个数恰好被选入一个序列之中。
并且满足限制:ci表示不小于i的数的个数,对于1≤i≤k都要满足。
现在问最少构成多少个序列。
保证c1≥c2≥⋯≥ck。
因为很明显大的数c就越小那么我们就从大到小枚举,用一个数组记录各个数组长度然后早到第一个len小于(这里不能等因为等的话加进这个数总len就超了)c[a[i]]的数组,我们有一个操作就是可以把长度设成负数就可以用upper_bound()
代码如下:
#include <iostream>
#include <cstdio>
#include <stack>
#include <sstream>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <cmath>
#include <deque>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#define mid ((l + r) >> 1)
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define _for(i,a,b) for( int i = (a); i < (b); ++i)
#define _rep(i,a,b) for( int i = (a); i <= (b); ++i)
#define for_(i,a,b) for( int i = (a); i >= (b); -- i)
#define rep_(i,a,b) for( int i = (a); i > (b); -- i)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define hash Hash
#define all(x) x.begin(),x.end()
#define next Next
#define f first
#define s second
using namespace std;
const int N = 2e5 + 10;
const double eps = 1e-9;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
inline LL read() {LL s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;
}
int a[N << 1], b[N << 1];
vector<int> ans[N];
int sz[N];//统计数组长度;
int main()
{int n, m;IOS;cin >> n >> m;_for(i,1,n+1) cin >> a[i];_for(i,1,m+1) cin >> b[i];sort(a+1,a+n+1);int arrsum = 0;for_(i,n,1){if(!arrsum){sz[++ arrsum] --;ans[arrsum].push_back(a[i]);}else{int pos = upper_bound(sz+1,sz+1+arrsum,-b[a[i]]) - sz;if(pos > arrsum) arrsum = pos;sz[pos] --;ans[pos].push_back(a[i]);}}cout << arrsum << endl;_for(i,1,arrsum+1){cout << -sz[i] << " ";for(auto it : ans[i])cout << it << " ";cout << endl;}return 0;
}
Educational Codeforces Round 86 (Rated for Div. 2)c和d相关推荐
- Educational Codeforces Round 86 (Rated for Div. 2) Apr/26/2020 22:35UTC+8
Educational Codeforces Round 86 Rated for Div. 2 A. Road To Zero B. Binary Period(找最小周期) C. Yet Anot ...
- Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)
Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...
- Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...
- Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...
- Educational Codeforces Round 37 (Rated for Div. 2) 1
Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...
- Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)
Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords 思路 题意非常简单,就是得到最多的物品嘛,我们假定a, ...
- Educational Codeforces Round 114 (Rated for Div. 2) D. The Strongest Build 暴力 + bfs
传送门 文章目录 题意: 思路: 题意: 你有nnn个装备槽,每个槽里面有cic_ici个力量加成,对于每个槽只能选一个力量加成,现在给你mmm个力量组合[b1,b2,...,bn][b_1,b_2 ...
- Educational Codeforces Round 72 (Rated for Div. 2) D. Coloring Edges dfs树/拓扑找环
传送门 文章目录 题意: 思路: 题意: 给你一张图,你需要给这个图的边染色,保证如果有环那么这个环内边的颜色不全相同,输出染色方案和用的颜色个数. n,m≤5e3n,m\le5e3n,m≤5e3 思 ...
- Educational Codeforces Round 111 (Rated for Div. 2) D. Excellent Arrays 组合数学
传送门 文章目录 题意: 思路: 题意: 给你一个数组aia_iai,定义一个数组是好的当且仅当对于所有iii都有ai!=ia_i!=iai!=i.定义f(a)f(a)f(a)表示数组aaa中i& ...
最新文章
- tlb存的什么_什么是MMU,TLB
- Android 获取屏幕尺寸与密度
- 高并发网络编程之epoll详解
- IOS对plist配置文件的读写操作
- Hystrix配置参数查找方式
- camunda流程引擎如此简单「四」
- C/C++人机猜拳游戏
- WCF三种通信模式(转)
- linux 运行eclipse,解决Linux下Eclipse启动错误
- 配对碱基链(信息学奥赛一本通-T1135)
- igm焊接机器人基本操作_焊接机器人编程与操作
- 红米开发版刷机教程_红米K30开发版刷机包(官方完整最新固件升级包MIUI12)
- 微信小程序——绘制时钟
- 为什么SICP要讨论那么多的初等数学
- Ubuntu Qt 无法覆盖文件 错误解决方法
- 使用pm2管理项目(指令)
- python 将QQ聊天记录生成词云图
- 基于cocos2d-lua的shader入门玩转
- Android-安卓Canvas画小黄人
- 一道面试题:StringBuffer a=new StringBuffer (A); StringBuffer b=new StringBuffer