B. Young Explorers

题目大意:给你n个人,每个人都有不同的经验值,现在要将这些人分组,每个人可以加入该组的条件就是他的经验值小于等于他所在组的规模,要求组数最多,有的人可以不加组
解题思路:很明显我们应该尽量小的经验值这样才能达到最大化组数,因为经验值越大,占用的人数就越多,组就越少
下面开代码:

#include <iostream>
#include <cstdio>
#include <stack>
#include <sstream>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <cmath>
#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 sfx(x) scanf("%lf",&x)
#define sfxy(x,y) scanf("%lf%lf",&x,&y)
#define sdx(x) scanf("%d",&x)
#define sdxy(x,y) scanf("%d%d",&x,&y)
#define pfx(x) printf("%.0f\n",x)
#define pfxy(x,y) printf("%.6f %.6f\n",x,y)
#define pdx(x) printf("%d\n",x)
#define pdxy(x,y) printf("%d %d\n",x,y)
#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 next Next
#define f first
#define s second
using namespace std;
const int N = 2e5 + 10, eps = 1e-10;
typedef long long LL;
typedef unsigned long long ULL;
map<int,int> r;
int a[N];
LL n, k;int main()
{IOS;int T;cin >> T;while(T --){cin >> n;_for(i,0,n)  cin >> a[i],r[a[i]] ++;sort(a,a+n);int res = 0;int cur = 1;_for(i,0,n){if(a[i] <= cur) res ++, cur = 1;else cur ++;}cout << res << endl;}return 0;
}


题目大意:给你三角形三条边的范围,问在这个范围内有可以构成多少个三角形
数学菜爆了
我们可以确定一条边去枚举其他两条边根据题意设最小的边的长度为i,根据第二条边的范围[B,C]–>确定第三条边的范围[B+i-1,C+i-1]。这个是(注意)[最大边的最大取值],题目还有一个范围[C,D]那么我们就可以确定这两个区间的交集
我们还要分类讨论两种情况:1.B+i-1 >= D ans += (D - C + 1) * (C - B + 1)
2.C + i - 1 >= D ans += (D - c + 1) * (C + i - 1 - D)

ll a,b,c,d;cin>>a>>b>>c>>d;ll ans=0;for(ll i=a;i<=b;i++){ll mn=i+b-1,mx=i+c-1;if(mn>=d) ans+=(d-c+1)*(c-b+1);else{ll l=max(mn,c),r=min(d,mx);ans+=(r-l+1)*(l-c+1+r-c+1)/2;if(mx>d) ans+=(mx-d)*(d-c+1);}}cout<<ans;

Codeforces Round #643 (Div. 2)B到C题解相关推荐

  1. Codeforces Round #643 (Div. 2) E. Restorer Distance 题解(三分)

    题目链接 题目大意 给你一个数组,要你使数组所有元素的值都相等且所消耗最小代价,增加1消耗a,减少1消耗r,转移1消耗m,求消耗最小代价 题目思路 如果增加减少都是1,转移是2,那么就是类似于仓库选址 ...

  2. Codeforces Round #643 (Div. 2) C. Count Triangles 题解(思维)

    题目链接 题目思路 显然是找x+y>z即可,其实只要枚举x+y即可,自己好菜qwq 代码 #include<cstdio> #include<algorithm> usi ...

  3. Codeforces Round #643 (Div. 2)(A, B, C, D, E)

    Codeforces Round #643 (Div. 2) Sequence with Digits 思路 一道暴力题,猜想在某一步一定会出现0,于是怀着忐忑提交了代码,结果还真的是这样. 代码 # ...

  4. Codeforces Round #807 (Div. 2)A~E个人题解

    Dashboard - Codeforces Round #807 (Div. 2) - Codeforces A. Mark the Photographer 题意: 有个人,每个人的身高设为,现在 ...

  5. Codeforces Round #706 (Div. 2)-A. Split it!-题解

    目录 Codeforces Round #706 (Div. 2)-A. Split it! Problem Description Input Output Sample Input Sample ...

  6. Codeforces Round #742 (Div. 2) B、C 题解

    Codeforces Round 742 B. MEXor Mixup 题意 有一个数组,输入两个数a,b,a代表这个数组之外的最小非负整数,b代表这个数组的异或值,问你该数组的最小长度. 思路 首先 ...

  7. Codeforces Round #643 (Div. 2)——B. Young Explorers

    题目链接: https://codeforces.com/problemset/problem/1355/B 题目描述: 输入探险家的经验级别,组队时一个队伍的人数不能少于队伍中任一人的经验级别(人数 ...

  8. Codeforces Round #643 (Div. 2)题解

    A . SequencewithDigitsSequence\ with\ DigitsSequence with Digits 首先数据范围就离谱,所以不管什么算法都不行,肯定是要找规律优化的. 我 ...

  9. Codeforces Round #643 (Div. 2)(AB)

    A: 思路:只有数字中出现0,那么后面就不会变动了.直接循环就可以,出现了0就退出. 代码如下: #include<bits/stdc++.h> #define ll long long ...

最新文章

  1. Java程序员从笨鸟到菜鸟之(八)反射和代理机制
  2. 温州大学《机器学习》课程课件(七、决策树)
  3. 大话数据结构12 串String
  4. Circle-Progress-View
  5. python数字字符串乘以2_Python基础(2)_数字和字符串类型
  6. Mysql 时间格式默认空串 ‘0000-00-00 00:00:00‘ select抛出异常的解决方法
  7. 文件比较命令:comm
  8. Emacs 配置 Python 编程环境
  9. /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start‘: (.text+0x20
  10. (池州市地图)行政区划图高清矢量cdr|pdf(详细版2021年)
  11. OpenCV 4 中文文档(更新mat部分)
  12. PS初学者(非设计专业人士)的碎碎念
  13. fluent的udf在windows可以编译 linux错误,fluent中udf环境变量设置,简单可行!已试过!...
  14. too few variables specified 怎么解决
  15. 【小白转型项目经理】实战案例14,总价合同如何向甲方申请其他费用补偿?
  16. 糯米粉可以做什么好吃的 糯米粉做法大全
  17. 雷军给陈年总结的小米十条经验
  18. rac集群状态中监听状态CHECK TIMED OUT处理
  19. 腾讯云数据库-劳动节小试牛刀-TDSQL-MySQL 云实例部署体验
  20. Hadoop实战-MR倒排索引(三)

热门文章

  1. 一文看懂95%置信区间
  2. 导师:学CV的不懂目标检测?那你别学了
  3. 对于SD-WAN安全的5个误区
  4. Eclipse Jetty 9.4.15 发布,建议使用 JDK 12
  5. 5 个用 Python 编写 web 爬虫的方法
  6. 比JD-GUI还要好用的Luyten
  7. JavaScript学习总结(十六)——Javascript闭包(Closure)
  8. CentOS 6 时间,时区,设置修改及时间同步
  9. MySQL Online DDL的改进与应用
  10. 2014年最值得关注的六大趋势