The Preliminary Contest for ICPC Asia Shanghai 2019 (B L )
B. Light bulbs
思路:差分 + 离散化, 好不容易懂了差分却没想到离散化,还是要罗老板出马....。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
std::ios::sync_with_stdio(false);
int t;
cin >> t;
for(int i = ;i <= t;i++)
{
int n, m;
cin >> n >> m;
map<int , int > mp;
while(m--){
int l, r;
cin >> l >> r;
mp[l] += ;
mp[r + ] -= ;
}
int last = , ans = , cnt = ;
for(auto it : mp)
{
ans += (it.first - last) * (cnt & );
cnt += it.second;
last = it.first;
}
cout << "Case #" << i << ": " << ans << endl;
}
return ;
}
L. Digit sum
思路:打个表,O(1)查询。
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + ;
ll dp[maxn][];
int main()
{
std::ios::sync_with_stdio(false);
int t;
cin >>t;
for(int i = ;i <= 1e6;i++)
{
for(int j = ;j <= ;j++){
dp[i][j] = ;
int tmp = i;
while(tmp){
dp[i][j] += tmp % j;
tmp /= j;
}
dp[i][j] += dp[i-][j];
}
}
for(int i = ;i <= t;i++)
{
int n, d;
cin >> n >> d;
cout << "Case #" << i << ": ";
cout << dp[n][d] << endl;
}
return ;
}
The Preliminary Contest for ICPC Asia Shanghai 2019 (B L )的更多相关文章
- The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力)
The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力) 传送门:https://nanti.jisuanke.com/ ...
- The Preliminary Contest for ICPC Asia Shanghai 2019
传送门 B. Light bulbs 题意: 起初\(n\)个位置状态为\(0\),\(m\)次操作,每次操作更换区间状态:\(0\)到\(1\),\(1\)到\(0\). 共有\(T,T\leq 1 ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 C. Triple
[传送门] FFT第三题! 其实就是要求有多少三元组满足两短边之和大于等于第三边. 考虑容斥,就是枚举最长边,另外两个数组里有多少对边之和比它小,然后就是 $n^3$ 减去这个答案. 当 $n \le ...
- 01背包方案数(变种题)Stone game--The Preliminary Contest for ICPC Asia Shanghai 2019
题意:https://nanti.jisuanke.com/t/41420 给你n个石子的重量,要求满足(Sum<=2*sum<=Sum+min)的方案数,min是你手里的最小值. 思路: ...
- 给定进制下1-n每一位数的共享(Digit sum)The Preliminary Contest for ICPC Asia Shanghai 2019
题意:https://nanti.jisuanke.com/t/41422 对每一位进行找循环节规律就行了. #define IOS ios_base::sync_with_stdio(0); cin ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 A. Lightning Routing I
传送门 因为某些原因,所以我就去学了 $LCT$ 维护直径, $LCT$ 维护直径我上一个博客讲得很详细了:传送门 这里维护虚儿子用的是 $multiset$ ,没写可删堆 #include<i ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 L. Digit sum
题目:https://nanti.jisuanke.com/t/41422 思路:预处理 #include<bits/stdc++.h> using namespace std; ][]= ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 J. Stone game
题目:https://nanti.jisuanke.com/t/41420 思路:当a(a∈S′)为最小值 如果Sum(S′)−a≤Sum(S−S′)成立 那么(∀t∈S′,Sum(S′)−t≤Sum ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 D. Counting Sequences I
题目:https://nanti.jisuanke.com/t/41412思路:dfs 先取ai>2 2^12>3000 因此至多取11个 其余用1补 ...
随机推荐
- 同时连接gitlab和github
---恢复内容开始--- 原文地址:https://juejin.im/post/5ac0cf356fb9a028df22c246 1. 分别生成gitlab和github的ssh key 生成第一个 ...
- oo前三次作业博客总结
第一次作业 实现多项式的加减运算,主要问题是解决输入格式的判断问题. 输入实例: {(3,0), (2,2), (12,3)} + {(3,1), (-5,3)} – {(-199,2), (29,3 ...
- 报警插件Alertmanager 安装与使用
Alertmanager是一个独立的告警模块,接收Prometheus等客户端发来的警报,之后通过分组.删除重复等处理,并将它们通过路由发送给正确的接收器:告警方式可以按照不同的规则发送给不同的模块负 ...
- Https socket 连接
介: 本文主要介绍了网络安全通讯协议 SSL/TLS 和 Java 中关于安全通讯的实现部分.并通过一个简单的样例程序实现,来展示如何在 Java 平台上正确建立安全通讯. 在人类建立了通信系统之后, ...
- C#设计模式:模板方法模式(Template Method)
一,我们为什么需要模板设计模式? 在程序设计中,可能每个对象都有共同的地方,而此时如果每个对象定义一次,如下例子,每个对象都写Stay()方法,这样在每个类中都有很多相同的代码,此时,我们需要用到模板 ...
- 数据库设计-Mysql数据库表设计的过程中几个关键点
一.表设计过程中应该注意的数据类型 1)更小的通常更好 控制字节长度 2)使用合适的数据类型: 如tinyint只占8个位,char(1024)与varchar(1024)的对比,char用于类似定长 ...
- Centos7下编译安装php扩展redis5.0.2
安装环境:centos7 + php 7.2.191. 下载地址:http://pecl.php.net/get/redis-5.0.2.tgz .tgz http://pecl.php.net/ge ...
- tomcat manager 禁止外网访问 只容许内网访问
参考:http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html A default Tomcat installation includes ...
- PHP微信红包生成算法的程序源码(用抛物线的模型实现)
代码如下: <?php /* * 红包生成随机算法 */ header("Content-type:text/html;charset=utf-8"); date_defau ...
- 小程序推送消息(Template)
最近搞小程序模拟推送消息,才发现小程序推送消息接口准备下线. 请注意,小程序模板消息接口将于2020年1月10日下线,开发者可使用订阅消息功能 咱们现在有需求,所以不管下不下,完成再说. 一:”获取a ...