hdu 1355 The Peanuts
http://acm.hdu.edu.cn/showproblem.php?pid=1355
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define maxn 10000
using namespace std; struct node
{
int x,y,w;
bool operator <(const node &a)const
{
return w>a.w;
}
}p[maxn];
int n,m,k; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&k);
int cnt=;
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
int xx;
scanf("%d",&xx);
if(xx)
{
p[cnt].x=i;
p[cnt].y=j;
p[cnt++].w=xx;
}
}
}
sort(p,p+cnt);
__int64 sum=,ans=;
for(int i=; i<cnt; i++)
{
if(i==)
{
sum+=p[i].x;
}
else sum+=abs(p[i].x-p[i-].x)+abs(p[i].y-p[i-].y);
if(sum+p[i].x+<=k)
{
ans+=p[i].w;
sum++;
}
else break;
}
cout<<ans<<endl;
}
return ;
}
hdu 1355 The Peanuts的更多相关文章
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
随机推荐
- 《Programming WPF》翻译 第6章 4.应用程序全球化
原文:<Programming WPF>翻译 第6章 4.应用程序全球化 如果你打算发布你的应用程序到全球各地,你可能需要为不同地区的用户界面准备不同的版本.至少,这需要解决将文本翻译成适 ...
- juicer模板引擎使用
http://www.juicer.name/ <script src="~/Scripts/jquery-1.8.2.min.js"></script> ...
- UVa12096.The SetStack Computer
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- dig命令(转载)
dig命令使用大全(linux上域名查询) 可以这样说,翻译本篇文档的过程就是我重新学习DNS的过程,dig命令可以帮助我们学习DNS的原理,配置,以及其查询过程.以前使用dig仅仅是查询一下A记录或 ...
- WPF最基本的4个引用
Windowsbase Windows基本类库 PresentationCore wpf核心类库 PresentationFramework wpf框架 System.Axml 系统类库
- Tomcat 常见问题篇
Tomcat 常见问题一.Tomcat常见问题 1.Tomcat web容器出现故障时,我们通过Tomcat自带的logs查看原因,以下错误提示都是源于logs 2.Connection refuse ...
- MySql命令——游标
1.游标的概念 有时,需要在检索出来的行中前进或后退一行或多行.这就是使用游标的原因.游标(cursor)是一个存储在 MySql 服务器上的数据库查询,它不是一条 select 语句,而是被该语句检 ...
- asp.net在后台弹出confirm确认对话框并获取用户选择的值做出相应的操作
在asp项目中,这种情况是经常出现的,前段时间通过查找资料以及自己尝试,找到一种解决方案,但是不知是否有更好的方案,以后发现再进行记录. 一.思路 在本次项目中,在一个函数中需要让用户判断,并根据用户 ...
- 在asp.net中导出表格Excel数据
第一步:需要引用org.in2bits.MyXls程序集到使用页面 第二步:前台代码 <asp:Button ID="LeadingOut" runat="serv ...
- Pull生成&解析
开篇注意,由于解析有可能有大文件非常耗时,建议另开一个线程解析也可以不开具体视情况而定 Pull生成 1.通过xml获得序列化的实例 XmlSerializer nxs = Xml.newSe ...