problem 1107
来源:互联网 发布:当当阅读器知乎 编辑:程序博客网 时间:2024/05/01 21:58
有点像那道monkey and banana ,要把图给放弃掉的。输入时过滤掉cheese小于(0,0)起点的部分,然后对cheese从大到小排序(这样(0,0)点就被放到了最后一个),m[i]表示以grid[i].x,grid[i].y为起点最多能吃到的cheese量,m[n](n是cheese大于起点的grid的数量)就是结果了。
有个让人火大的地方,就是fatmouse居然笨到不会拐弯,FT!
Accepted 1107 C 00:03.58 660K#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define MAXN 100
struct s
{
int cheese,x,y;
}grid[MAXN * MAXN];
int cmp(const void* a,const void* b)
{
return ((struct s*)b)->cheese - ((struct s*)a)->cheese;
}
void solve(int n,int k)
{
int i,j;
int m[MAXN * MAXN],cnt = 1;
scanf("%d",&grid[0].cheese);
grid[0].x = grid[0].y = 0;
for (i = 1; i < n * n; i++)
{
int temp;
scanf("%d",&temp);
if (temp > grid[0].cheese)
{
grid[cnt].x = i % n;
grid[cnt].y = i / n;
grid[cnt].cheese = temp;
cnt++;
}
}
if (k == 0) { printf("%d ",grid[0].cheese); return; }
qsort(grid,cnt,sizeof(grid[0]),cmp);
for (i = 0; i < cnt; i++)
{
m[i] = grid[i].cheese;
for (j = 0; j < i; j++)
{
if (grid[i].cheese < grid[j].cheese && abs(grid[j].x - grid[i].x) <= k && abs(grid[j].y - grid[i].y) == 0 &&
m[i] < m[j] + grid[i].cheese)
m[i] = m[j] + grid[i].cheese;
if (grid[i].cheese < grid[j].cheese && abs(grid[j].x - grid[i].x) == 0 && abs(grid[j].y - grid[i].y) <= k &&
m[i] < m[j] + grid[i].cheese)
m[i] = m[j] + grid[i].cheese;
}
}
printf("%d/n",m[cnt - 1]);
}
void main()
{
int n,k;
#ifndef ONLINE_JUDGE
freopen("1107.txt","r",stdin);
#endif
while(scanf("%d%d",&n,&k) != EOF && !(k == -1 && n == -1))
solve(n,k);
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
}
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define MAXN 100
struct s
{
int cheese,x,y;
}grid[MAXN * MAXN];
int cmp(const void* a,const void* b)
{
return ((struct s*)b)->cheese - ((struct s*)a)->cheese;
}
void solve(int n,int k)
{
int i,j;
int m[MAXN * MAXN],cnt = 1;
scanf("%d",&grid[0].cheese);
grid[0].x = grid[0].y = 0;
for (i = 1; i < n * n; i++)
{
int temp;
scanf("%d",&temp);
if (temp > grid[0].cheese)
{
grid[cnt].x = i % n;
grid[cnt].y = i / n;
grid[cnt].cheese = temp;
cnt++;
}
}
if (k == 0) { printf("%d ",grid[0].cheese); return; }
qsort(grid,cnt,sizeof(grid[0]),cmp);
for (i = 0; i < cnt; i++)
{
m[i] = grid[i].cheese;
for (j = 0; j < i; j++)
{
if (grid[i].cheese < grid[j].cheese && abs(grid[j].x - grid[i].x) <= k && abs(grid[j].y - grid[i].y) == 0 &&
m[i] < m[j] + grid[i].cheese)
m[i] = m[j] + grid[i].cheese;
if (grid[i].cheese < grid[j].cheese && abs(grid[j].x - grid[i].x) == 0 && abs(grid[j].y - grid[i].y) <= k &&
m[i] < m[j] + grid[i].cheese)
m[i] = m[j] + grid[i].cheese;
}
}
printf("%d/n",m[cnt - 1]);
}
void main()
{
int n,k;
#ifndef ONLINE_JUDGE
freopen("1107.txt","r",stdin);
#endif
while(scanf("%d%d",&n,&k) != EOF && !(k == -1 && n == -1))
solve(n,k);
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
}
- problem 1107
- problem
- Problem
- problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- java虚拟机类的加载顺序
- 变量
- JS等比例缩放图片
- 上拉电阻下拉电阻的总结
- 电平转换总结(ZZ)
- problem 1107
- 方法和变量在继承时的覆盖与隐藏--摘抄JDK实例宝典
- sharePoint安装过程中创建数据库或应用程序池最好要用administrator帐号
- ASP.NET编程中的十大技巧
- A Greek to Remember
- Apache与Tomcat的区别 ,几种长见得web/应用服务器
- 七夕OX节日程安排
- 比较简单的mssql数据库日志文件收缩方法
- Friends