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 )的更多相关文章

  1. 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/ ...

  2. The Preliminary Contest for ICPC Asia Shanghai 2019

    传送门 B. Light bulbs 题意: 起初\(n\)个位置状态为\(0\),\(m\)次操作,每次操作更换区间状态:\(0\)到\(1\),\(1\)到\(0\). 共有\(T,T\leq 1 ...

  3. The Preliminary Contest for ICPC Asia Shanghai 2019 C. Triple

    [传送门] FFT第三题! 其实就是要求有多少三元组满足两短边之和大于等于第三边. 考虑容斥,就是枚举最长边,另外两个数组里有多少对边之和比它小,然后就是 $n^3$ 减去这个答案. 当 $n \le ...

  4. 01背包方案数(变种题)Stone game--The Preliminary Contest for ICPC Asia Shanghai 2019

    题意:https://nanti.jisuanke.com/t/41420 给你n个石子的重量,要求满足(Sum<=2*sum<=Sum+min)的方案数,min是你手里的最小值. 思路: ...

  5. 给定进制下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 ...

  6. The Preliminary Contest for ICPC Asia Shanghai 2019 A. Lightning Routing I

    传送门 因为某些原因,所以我就去学了 $LCT$ 维护直径, $LCT$ 维护直径我上一个博客讲得很详细了:传送门 这里维护虚儿子用的是 $multiset$ ,没写可删堆 #include<i ...

  7. The Preliminary Contest for ICPC Asia Shanghai 2019 L. Digit sum

    题目:https://nanti.jisuanke.com/t/41422 思路:预处理 #include<bits/stdc++.h> using namespace std; ][]= ...

  8. 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 ...

  9. 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补        ...

随机推荐

  1. pdf兼容问题不能正常预览

    刚开始以为是这个PDF文件过大导致的 发现其他更大的文件也能正常显示 考虑到PDF的兼容问题 由于导出的PDF格式不兼容导致,如果有这种情况,可以尝试用word2016打开pdf文件,再导出成pdf.

  2. Vue2.0---webpack打包知识点-2

    先贴一篇对vue-cli#2.0进行webpack配置的详细分析: https://zhuanlan.zhihu.com/p/24322005 一.看一下webpack的打包流程 1.package. ...

  3. Cocos2d-x之Map<K, V>

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. Map<K, V>是Cocos2d-x 3.0x中推出的字典容器,它也能容纳Ref类型.Map<K,V>是模仿C+ ...

  4. opencv图像的基本操作3

    1.获取像素并修改 读取一副图像,根据像素的行和列的坐标获取它的像素值,对于RGB图像而言,返回RGB的值,对于灰度图则返回灰度值 import cv2 import numpy img = cv2. ...

  5. matplotlib系列——中文显示

    幕布视图:https://mubu.com/doc/alG8r_3iSw 参考文献:嵩天的Python课程讲义 方式一: 示例 rcParams的属性 方式二:(推荐使用) 示例: 中文字体种类

  6. HDU 1577 WisKey的眼神

    WisKey的眼神 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  7. C中进制, 原码, 反码与补码的简单用法

    /** * 二进制 binary 如: 1010 * 八进制 octal 如: 070 * 十六进制 hexadecimal 如: 0x7f * * 1Byte = 8bits * 1WORD = 2 ...

  8. 2019-8-31-C#-使用汇编

    title author date CreateTime categories C# 使用汇编 lindexi 2019-08-31 16:55:58 +0800 2019-2-16 8:56:5 + ...

  9. Vue的路有拦截与axios的封装

    一丶首先我们先创建api与utils两个文件夹 二丶api文件夹里面新建文件api.js import request from "../utils/http" import qs ...

  10. oracle死锁查询

    select sess.sid ||','|| sess.serial#, lo.oracle_username, lo.os_user_name, ao.object_name, lo.locked ...