GPCPC_01_An_Easy_Problem

题目描述

Measuring the area of a certain shape is an important part of certain geometric problems.

For a point A(x,y) on the plane, we define the F(x,y) as ∣x∣∗∣y∣,which means the area of the rectangle with the vertex(x,0),(0,y),(0,0),(x,y).

You are given n∗m vertex with integral coordinates in the form of (i,j),and 1≤i≤n,1≤j≤m. You need to find the K-th biggest value of F(i,j),when 1≤i≤n,1≤j≤m.

It’s guranteed that K≤n∗m.

输入描述:

Three integers n,m,Kn,m,K_{}n,m,K(1≤n,m,K≤1061\leq n,m,K\leq 10^61≤n,m,K≤106). 

输出描述:

One integer,the K-th biggest value of F(i,j)F(i,j)_{}F(i,j).

示例1

输入

3 3 4

输出

4

说明

In this eaxmple, the values of all F(i,j) are 1,2,2,3,3,4,6,6,9.

So the 4-th biggest value of F(i,j)F(i,j)_{}F(i,j) is 4.
题目大意:

输入两个数n,m,k.得到从1-n 分别乘以 1-m的数.然后排列输出第K大的数

解题思路:

声明:这是看了别的大佬的做法后自己仿造的.如有侵犯请联系我删除.

利用set容器中pair中一个记录最大值,另外一个是产生最大值的数.然后最大值减去这个数再插入回容器.set容器根据值的大小排序,所以顶上一直是最大值,减一次就会产生第二大的数.以此类推可以产生排在第几的数.

限制

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

代码:
#include<iostream>
#include<set>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;

typedef pair < ll, ll> pll;

set<pll> pg;

int main()
{
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 0; i <= n; ++i)
	{
		pg.insert(pg.begin(),{ i * m,i });
	}
	k--;
	while (k--)
	{
		set<pll>::iterator it = pg.end();
		it--;
		ll val = it->first;
		ll line = it->second;

		pg.insert(pg.end(),{ val - line,line });
		pg.erase(it);
	}
	set<pll>::iterator it = --pg.end();
	cout << it->first << endl;

	return 0;
}
运行结果

运行结果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

公仔面i

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值