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补 ...
随机推荐
- PHP+JS的信息提示弹窗
基于PHP函数的Msg信息提示框 1.可以设置弹出信息,跳转地址,跳转的时间,跳转的信息标题提示: 2.代码实例: <?php function ShowMsg($msg, $gourl,$ti ...
- 3天教你掌握Python必备常用英语词汇
第一天 path [ pɑ:θ ] 路径 unexpected [ˌʌnɪkˈspektɪd] 不期望的 class [klɑ:s] 类 usage [ˈju:sɪdʒ] 使用 public ['p ...
- jQuery设置checkbox 为选中状态
1设置第一个checkbox 为选中值$('input:checkbox:first').attr("checked",'checked');或者$('input:checkbox ...
- docker 实战
创建镜像 docker pull ubuntu 创建容器 docker run -it -name web ubuntu /bin/bash 更新软件源信息 apt-get update 安装ssh ...
- linux缺頁異常處理--內核空間[v3.10]
缺頁異常被觸發通常有兩種情況—— 1.程序設計的不當導致訪問了非法的地址 2.訪問的地址是合法的,但是該地址還未分配物理頁框 下面解釋一下第二種情況,這是虛擬內存管理的一個特性.盡管每個進程獨立擁有3 ...
- Visual Studio Code如何编写运行C、C++
Visual Studio Code如何编写运行C.C++ 作者:知乎用户链接:https://www.zhihu.com/question/30315894/answer/154979413来源:知 ...
- ubunut 1804 sublime text3
—– BEGIN LICENSE —– TwitterInc User License EA7E- 1D77F72E 390CDD93 4DCBA022 FAF60790 61AA12C0 A3708 ...
- redux和react-redux
redux和react-redux的关系: redux是react的状态管理工具,却不仅仅只是为了react而生的,所以在使用中会存在痛点.而react-redux是专门为了react定制,目的是为了 ...
- SpringBoot2.x整合Shiro(一)
一:什么是ACL和RBAC: ACL: Access Control List 访问控制列表 以前盛行的一种权限设计,它的核心在于用户直接和权限挂钩 优点:简单易用,开发便捷 缺点:用户和权限直接挂钩 ...
- JAVA 实现Jacob语音播报
准备工作:下载Jar 链接:https://pan.baidu.com/s/1edskJjYrCiefVJ7l3Ul9kQ 提取码:6dg9 ---导入jar 解压jar包,将jacob.ja ...