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补 ...
随机推荐
- Hibernate注解详解(超全面不解释)
原博客地址:http://blog.csdn.net/sufei58/article/details/48223731 我只是收藏来方便自己查阅的,希望博主不要介意 一.实体Bean 每个持久化POJ ...
- 如何使用iText制作中文PDF
1. 下载itextpdf.jar 基础包:http://jaist.dl.sourceforge.net/project/itext/iText/iText5.5.2/itext-5.5.2.zip ...
- 查看x86主機是否支援64bit in Linux
$cat /proc/cpuinfo 查看flags 欄位中是否有 lm (long mode)
- 博弈的dfs
题目: 链接:https://ac.nowcoder.com/acm/contest/283/D来源:牛客网 小西买了一堆肥宅快乐水和肥宅快乐茶,准备和室友比谁更肥宅. 快乐水有A瓶,快乐茶B瓶. 小 ...
- cnblogs博客主题原来可以弄得这么美观
参考了网友 https://www.cnblogs.com/maybreath/p/5253824.html的做法,没想到真的可以耶. 总想弄个方便的.简洁的.可以被搜索引擎搜到的博客.以前用过wor ...
- 利用powerDesigner15.1连接oracle数据库并自动生成表结构
利用powerDesigner15.1连接oracle数据库并自动生成表结构 参考:http://blog.csdn.net/qq_24531461/article/details/76713802 ...
- 【记录】Mysql 建表注意事项
博主最近打算搭建商城,由于之前对建表只有很浅显的理解,没有太过深入了解,建表过程中遇到一些问题,现记录如下, 如有问题请各位留言指正,感激不尽: 建表时设置如何设置联合主键?如下标红处: CREATE ...
- 联想think system sr550信息
带外管理口 默认IP地址:192.168.70.125 默认用户名密码 USERID PASSW0RD 0是数字0
- 线程监控ProcessMonitor
软件行为 在线监测 注册表 行为判断
- 【串线篇】SpringMVC运行流程
1.所有请求,前端控制器(DispatcherServlet)收到请求,调用doDispatch进行处理 2.根据HandlerMapping中保存的请求映射信息找到,处理当前请求的,处理器执行链(包 ...