计蒜客 2018南京赛区网络赛 The writing on the wall 暴力dp

量化策略开发步骤系列(5)前向测试和统计意义 我们在第 4 部分,展示了我们策略的样本外测试并讨论了其结果。用于开发模型的数据是 2018 年至 2021 年的数据,测试数据是 2021 年至 2022 年的数据。但有一种方法可以更好地利用我们的数据。 阅读详情

题目链接:https://nanti.jisuanke.com/t/30991

Feeling hungry, a cute hamster decides to order some take-away food (like fried chicken for only 3030 Yuan).

However, his owner CXY thinks that take-away food is unhealthy and expensive. So she demands her hamster to fulfill a mission before ordering the take-away food. Then she brings the hamster to a wall.

The wall is covered by square ceramic tiles, which can be regarded as a n * mn∗m grid. CXY wants her hamster to calculate the number of rectangles composed of these tiles.

For example, the following 3 * 33∗3 wall contains 3636 rectangles:

Such problem is quite easy for little hamster to solve, and he quickly manages to get the answer.

Seeing this, the evil girl CXY picks up a brush and paint some tiles into black, claiming that only those rectangles which don't contain any black tiles are valid and the poor hamster should only calculate the number of the valid rectangles. Now the hamster feels the problem is too difficult for him to solve, so he decides to turn to your help. Please help this little hamster solve the problem so that he can enjoy his favorite fried chicken.

Input

There are multiple test cases in the input data.

The first line contains a integer TT : number of test cases. T \le 5T≤5.

For each test case, the first line contains 33integers n , m , kn,m,k , denoting that the wall is a n \times mn×m grid, and the number of the black tiles is kk.

For the next kk lines, each line contains 22integers: x\ yx y ,denoting a black tile is on the xx-th row and yy-th column. It's guaranteed that all the positions of the black tiles are distinct.

For all the test cases,

1 \le n \le 10^5,1\le m \le 1001≤n≤105,1≤m≤100,

0 \le k \le 10^5 , 1 \le x \le n, 1 \le y \le m0≤k≤105,1≤x≤n,1≤y≤m.

It's guaranteed that at most 22 test cases satisfy that n \ge 20000n≥20000.

Output

For each test case, print "Case #xx: ansans" (without quotes) in a single line, where xx is the test case number and ansans is the answer for this test case.

Hint

The second test case looks as follows:

样例输入复制

2
3 3 0
3 3 1
2 2

样例输出复制

Case #1: 36
Case #2: 20

dp【i】【j】代表以方块ij为左上角的矩阵数目。一边维护一边加。

按行优先从后向前遍历,同时维护到当前为止每一行最右侧被挖掉的方块,每一列最上边被挖掉的方块。如果某个方块下面或者右面的方块被挖掉,则以它作为左上角的矩阵数等于同行或者同列到挖掉为止的最大值。否则暴力计算符合条件的方块数。注意要沿着列计算,因为m最大为100,这样不会t(虽然不知道为什么。。)。

  • #include<bits/stdc++.h>
    #define inf 0x3f3f3f3f
    #define mod 1000000007
    #define For(i,m,n) for(int i=m;i<=n;i++)
    #define Dor(i,m,n) for(int i=m;i>=n;i--)
    #define LL long long
    #define lan(a,b) memset(a,b,sizeof(a))
    using namespace std;
    
    int vis[100010][110];
    LL dp[100010][110];
    int line[100010],clu[100010];
    
    int main()
    {
        int t;
        scanf("%d",&t);
        For(tt,1,t)
        {
            int n,m,k;
            scanf("%d%d%d",&n,&m,&k);
            lan(vis,0);
            For(i,1,n)
                line[i]=m+1,dp[i][m+1]=0;
            For(i,1,m)
                clu[i]=n+1,dp[n+1][i]=0;
            while(k--)
            {
                int x,y;
                scanf("%d%d",&x,&y);
                vis[x][y]=1;
            }
            LL sum=0;
            for(int i=n;i>=1;i--)
            {
                for(int j=m;j>=1;j--)
                {
                    if(vis[i][j]==1)
                    {
                        line[i]=j;
                        clu[j]=i;
                        dp[i][j]=0;
                        continue;
                    }
                    if(vis[i][j+1]==1)
                    {
                        dp[i][j]=clu[j]-i;
                    }
                    else if(vis[i+1][j]==1)
                    {
                        dp[i][j]=line[i]-j;
                    }
                    else
                    {
                        int minn=inf;
                        LL ans=0;
                        For(k,j,line[i]-1)
                        {
                            if(clu[k]<minn)
                                minn=clu[k];
                            ans+=minn-i;
                        }
                        dp[i][j]=ans;
                    }
                    sum+=dp[i][j];
                }
            }
    
    //        For(i,1,n)
    //        {
    //            For(j,1,m)
    //            {
    //                printf("%d\t",dp[i][j]);
    //
    //            }
    //            printf("\n");
    //        }
            printf("Case #%d: %lld\n",tt,sum);
    
        }
        return 0;
    }
    

     

华为面试手撕真题【判断是ipv4还是ipv6地址】 编写一个函数来验证输入的字符串是否是有效的 IPv4 或 IPv6 地址。 阅读详情

相关推荐

机器视觉/将HIK海康面阵相机连接Halcon软件

本文简述了如何将海康面阵相机连接到Halcon软件中进行实时取图的过程。

Dahe.qu 4866

ACM-ICPC 2018 南京赛区网络预赛 B The writing on the wall

题目链接 题意:一个n*m的方格矩阵,有的格子被涂成了黑色,问该矩阵中有多少个子矩阵,子矩阵不包含黑色格子; 思路:对于一个长为L, 高为H的无黑点矩阵中包含的高为H的子矩阵个数为L+(L-1)+(L-2)+...+1个;这是直接算的一种方法;如何程序表示该计算呢? for(int i=1; i&lt;=L; i++){ for(int j=i; j&gt;0; j--){ ...

Sirius_han的博客 1899

提取abaqus中节点集合的应力应变

节点是没有应力应变的,只有积分点才有,所以直接在odb文件里面用FieldOutput是整不出来的(结果是个空列表),只能用session这种让abaqus自己帮你处理。具体的代码需要根据自己操作的时候abaqus.rpy这个文件中代码的变化来更改。

蓝胖子的博客 4553

ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall

题意: 方格矩形中不包括一些点,能形成多少个子矩形 思路: n*m遍历每个点,维护一下每个点最高可以到达的高度,遍历每行的点的时候,把这个点当做矩形的右下角,看能形成多少个矩形,即从这个点向左,可以到达的最大高度的和 #include &lt;bits/stdc++.h&gt; using namespace std; #define ll long long #define max_ ...

Lngxling的博客 441

ESP32 Arduino 学习篇(五)TFT_eSPI库

该库有User_Setup.h和 User_Setup_Select.h两个配置文件,支持 ①自定义参数或 ②使用已有配置 驱动TFT屏幕。优点是: 1. 占用空间非常小 2. 动画清晰,充分利用每个像素点 3. 可以非常灵动. 4. 方便进行微调。首先在Libraries里面搜索安装TFT_eSPI库到你的工程文件里面。初始化屏幕, 如果是ST7735,可以往里面传一个参数, 具体用到时再看。缺点是: 1. 容易闪屏 2. 一般不会太复杂 3.需要大量的计算。特别注意: 字库7是仿7段数码屏的样式。

DOF526570的博客 2万+

GCJ02坐标系转WGS84坐标系(已实地测试基本无偏差)

坐标系转化,GCJ02坐标系,WGS84坐标系

Xiao_XianYu_的博客 1855

2018 ICPC南京站网络赛 The writing on the wall(单调栈求全1子矩阵数量)

Feeling hungry, a cute hamster decides to order some take-away food (like fried chicken for only 3030 Yuan). However, his owner CXY thinks that take-away food is unhealthy and expensive. So she deman...

untilyouydc 809

ArcGIS符号库下载 | 制图规范、三调、1:1万地形图、土地利用总体规划图.....

最近整理了一些符号库 涉及的类型比较多 包含有三调的(二调的也加上去了),一些点线面符号库,1:1万地形图,1:5万土地利用,土地利用总体规划图

qq_43173805的博客 2万+

ACM-ICPC 2018 南京赛区网络预赛 The_writing_on_the_wall 单调栈 思路

The writing on the wall  2000ms  262144K Feeling hungry, a cute hamster decides to order some take-away food (like fried chicken for only 30 Yuan). However, his owner CXY thinks that take-away food...

OtterVのrecorder 319

vLLM专题(七)-支持的模型列表

vLLM支持跨多种任务的生成式和池化模型。如果一个模型支持多个任务,您可以通过–task参数来设置任务。对于每个任务,我们列出了已在vLLM中实现的模型架构。每个架构旁边,我们列出了一些使用该架构的流行模型。

1258

【TRAE调教指南之MCP篇】Context 7 MCP:让AI永远拥有最新技术文档

【TRAE调教指南之MCP篇】Context 7 MCP:让AI永远拥有最新技术文档

funfan的博客 1314

2018 icpc 南京网络赛

题目:链接 A. An Olympian Math Problem 输出n-1即可(女朋友猜的)。 #include&lt;bits/stdc++.h&gt; using namespace std; #define ll long long ll fac[103]; int main() { ll n,T;cin&gt;&gt;T; while(T--) { ...

albertluf的博客 2357

【漏洞复现】爱数云盘 Usrm_GetAllUsers 未授权访问漏洞

爱数 AnyShare存在未授权漏洞,未授权的攻击者可以通过该漏洞获取用户名信息。

qq_67810151的博客 3121

计蒜客 AC Challenge (2018 ICPC亚洲区域赛网络赛 南京 E)(状压DP)

题目链接:https://nanti.jisuanke.com/t/30994   Dlsj is competing in a contest with n (0 &lt; n \le 20)n(0&lt;n≤20) problems. And he knows the answer of all of these problems. However, he can submit ii-t...

LP_Cong 1372

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

2018ACM/ICPC南京网络赛B-The writing on the wall (补题)

题目链接 题意:求n*m的区域中不含有黑色格子的矩形数量。 这题给了2s的时限,m只给了100,暴力复杂度可以是O(n*m*m),接近1e9,能过,大概1300+ms。。。因为高中的时候懒得学组合数学,导致现在对计数的东西一窍不通,连没有黑色格子的情况居然都想不清楚QAQ 这是一篇讲解本题的博客 看了上面链接的博客后,有种恍然大明白的感觉,现在开始讲讲我理解的做法。 首先,假设没有黑...

qq_38515845的博客 745

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

ACM-ICPC 2018 南京赛区网络预赛 B-The writing on the wall

Feeling hungry, a cute hamster decides to order some take-away food (like fried chicken for only 3030 Yuan). However, his owner CXY thinks that take-away food is unhealthy and expensive. So she deman...

一只小陀螺的博客 746

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

ACM-ICPC 2018 南京赛区网络预赛 B The writing on the wall(暴力)

ACM-ICPC 2018 南京赛区网络预赛 B The writing on the wall 这道题不想写了,直接看我队友的写的博客吧,网上其他博客其他方法我也看不懂。。 ACM-ICPC 2018 南京赛区网络预赛 B The writing on the wall code: #include &lt;bits/stdc++.h&gt; using namespace std; t...

codeswarrior的博客 823

ACM-ICPC 2018 南京赛区网络预赛

这次服务器很流畅,比赛体验很棒,上次杭电那场真的是气到爆炸交了题要三个小时才知道结果 要有计蒜客就算超时了也可以看到超了多少(1000ms以上会显示1009ms) 队友这次有点迷茫,两个人卡在最后那道图论题3个小时,结果还是我转过去暴力过的,所以今天做出来的四道基本上是我一个人敲出来的。所以说个人的实力还是很重要的,我们这边的一队两个人就做出10道题排名34。。。望尘莫及啊!不过还好,我才学了...

QAQ 1096

ACM-ICPC 2018 南京赛区网络预赛 B-The writing on the wall 暴力or经典单调栈

Feeling hungry, a cute hamster decides to order some take-away food (like fried chicken for only 303030 Yuan). However, his owner CXY thinks that take-away food is unhealthy and expensive. So she dem...

人生如戏 315

ACM-ICPC 2018 南京赛区网络预赛 J.Sum(线性筛选,分解质因数)

题目链接:Sum 样例输入 2 5 8 样例输出 8 14 题意:定义f[i]函数代表i=a*b的对数,其中a和b都不能是平方数的倍数,a*b与b*a不相同,t组样例,给出n,求1~n的f[i]之和 思路:一个数n分解质因数为 ,且有,容易得到这样的规律,遍历所有的e,当e=1时,f[i]=f[i]*2,当e=2时,f[i]不变,当e&gt;2时,f[i]=0。如果直接一个一个分解质因...

yz467796454的博客 1133

计蒜客 ICPC南京网络赛 The Great Nim Game(线性基)

      大致题意:Nim游戏,是指有n堆石子,每堆石子有ai个石子,两个人轮流取,每次可以取一堆的至少一个石子,最后取不的人输。现在告诉你总共有N堆石子,这个N很大,可以有10^10000000这么大,然后每一堆的石子数量有一个产生式。你的任务是在这N堆石子中,任意选取几堆石子,使得先手必胜,问方案数。 首先,根据定理,Nim游戏要使得先手必胜,必须要所有堆的石子数量的...

alpc_qleonardo 502

南京网络赛B-The writing on the wall

 30.43%  2000ms  262144K Feeling hungry, a cute hamster decides to order some take-away food (like fried chicken for only 3030 Yuan). However, his owner CXY thinks that take-away food is unhealthy ...

wybooooooooo的博客 271

ACM-ICPC 2018南京赛区网络预赛 J Sum(线性筛)

A square-free integer is an integer which is indivisible by any square number except 11. For example, 6 = 2 \cdot 36=2⋅3 is square-free, but 12 = 2^2 \cdot 312=22⋅3 is not, because 2^222 is a square n...

yypurpose的博客 1031

2018ICPC南京赛区网络选拔B The writing on the wall (单调栈)

2018ICPC南京赛区网络选拔B The writing on the wall (单调栈) 题目链接: https://nanti.jisuanke.com/t/30991 代码: #include&amp;lt;bits/stdc++.h&amp;gt; using namespace std; const int maxn=1e5+5; #define push_back pb; vect...

Dyswan的博客 202

ACM-ICPC 2018 南京赛区网络预赛---总结

ACM-ICPC 2018 南京赛区网络预赛 总结 与dq队差距 4题 A 水题 B pair卡常 补题链接:https://blog.youkuaiyun.com/axuhongbo/article/details/82289535 E 裸状压dp http://www.cnblogs.com/dilthey/p/9570205.html my_code #includ...

axuhongbo的博客 2182

ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall(暴力,单调栈)

ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall 题目 给一个 n * m 的矩阵,和 k 个矩阵上的污点,问没有在污点上的子矩阵有多少。 分析 首先想如果没有污点,怎么算所有矩阵。 枚举子矩阵右下角,n * m种情况。在确定子矩阵右下角为 (i, j)时,考虑长宽,因为本题 m 范围 100,所以枚举宽,1~m,每种宽对应 i 种高。代码: f...

Stormjing的博客 385
上一篇: hdu 6394 树分块
下一篇: hdu 6373 Pinball
Dale_zero
博客等级 码龄9年 10粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值