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. [python面试题] 什么是单例,单例有什么用,业务场景是什么

    单例概念: 单例是一个特殊的类,这个类只能创建一次实例,例子如下: 1.a = Std(name='leo'), b = Std(name='jack'),两者的指向都是name=‘leo’的对象: ...

  2. day 101 天

    一.新建项目 +安装bootstrap 安装bootstrap组件 二.Vue-route的使用 1. router.js配置文件 2. vue文件 3. Header.js文件

  3. Infinity、-Infinity和NaN

    首先看看这三个代表什么: Infinity:正无穷大 -Infinity:负无穷大 NaN:Not a Number 当float或double类型的数除零时, 当被除数为非零值时,结果为无穷大 当被 ...

  4. python面试题之请谈谈.pyc文件和.py文件的不同之处

    虽然这两种文件均保存字节代码,但.pyc文件是Python文件的编译版本,它有平台无关的字节代码,因此我们可以在任何支持.pyc格式文件的平台上执行它.Python会自动生成它以优化性能(加载时间,而 ...

  5. ArcGIS 面要素缝隙孔洞检查代码 C# GP

    public class PolygonGapChecker : CheckProgressMessageSender, IChecker, ICheckProgressChangeEvent { p ...

  6. python opencv 生成验证码

    基本思路是使用opencv来把随机生成的字符,和随机生成的线段,放到一个随机生成的图像中去. 虽然没有加复杂的形态学处理,但是目前看起来效果还不错 尝试生成1000张图片,但是最后只有998张,因为有 ...

  7. 向服务器发送post请求

    /** * 通过HttpClient发送Post请求 * @param path 请求路径 * @param params 请求参数 * @param encoding 编码 * @return 请求 ...

  8. 【原创】微信最新表情js代码

    最近在做仿微信聊天表情发送功能,所以需要展示常用的105个表情. 因为对接微信公众号的时候,用户聊天过程中发送的表情,微信服务器会转成对应的代码传给我们的服务器,类似如下: :/::)/::~/::B ...

  9. wxDateTime用法和转换成wxString

    转载别人的.void datetest() { wxDateTime now=wxDateTime::Now(); wxString date1=now.Format(); wxString date ...

  10. 五、bootstrap-Table Treegrid

    一.bootstrap-Table Treegrid <!DOCTYPE HTML> <html lang="zh-cn"> <head> &l ...