zoukankan      html  css  js  c++  java
  • [luoguP1086] 花生采摘(模拟)

    传送门

    模拟。。。


    代码

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #define abs(x) ((x) < 0 ? -(x) : (x))
    
    int n, m, k, cnt, ans;
    
    struct node
    {
    	int v, x, y;
    }p[1001];
    
    inline int read()
    {
    	int x = 0, f = 1;
    	char ch = getchar();
    	for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    	for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
    	return x * f;
    }
    
    inline bool cmp(node x, node y)
    {
    	return x.v > y.v;
    }
    
    inline int query(int i, int j)
    {
    	return abs(p[i].x - p[j].x) + abs(p[i].y - p[j].y);
    }
    
    int main()
    {
    	int i, j, x;
    	n = read();
    	m = read();
    	k = read();
    	for(i = 1; i <= n; i++)
    		for(j = 1; j <= m; j++)
    			if(x = read())
    				p[++cnt].v = x, p[cnt].x = i, p[cnt].y = j;
    	std::sort(p + 1, p + cnt + 1, cmp);
    	if(p[1].x * 2 + 1 <= k) ans += p[1].v, k -= p[1].x + 1;
    	else
    	{
    		puts("0");
    		return 0;
    	}
    	for(i = 2; i <= cnt; i++)
    	{
    		if(query(i - 1, i) + p[i].x + 1 > k)
    		{
    			printf("%d
    ", ans);
    			return 0;
    		}
    		ans += p[i].v;
    		k -= query(i - 1, i) + 1;
    	}
    	printf("%d
    ", ans);
    	return 0;
    }
    

      

  • 相关阅读:
    2018.7.9 模拟赛
    树状数组||归并排序求逆序对+离散化 nlogn
    LCS nlogn
    孤岛营救问题
    [POJ 3621] Sighting Cows
    树状数组求LIS
    nlogn求逆序对&&陌上花开
    最长可重区间集
    LCA模板
    [BZOJ] 4196 [Noi2015]软件包管理器
  • 原文地址:https://www.cnblogs.com/zhenghaotian/p/7079594.html
Copyright © 2011-2022 走看看