跳到正文

个人记录

贪心总结

the133lvlone约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年10月5日
收录
2026年10月11日
更新
2026年11月11日
篇幅
约 2 分钟

版本

  1. v1当前

总结

T1

C++
#include<bits/stdc++.h>
using namespace std;
string a[22];
int b;
bool c(string d,string e)
{
	return d+e>e+d;
}
signed main()
{
	cin>>b;
	for(int i=0;i<b;i++)
	{
		cin>>a[i];
	}
	sort(a,a+b,c);
	for(int i=0;i<b;i++)
	{
		cout<<a[i];
	}
}
php
两个字符串拼起来选大的,拼起来的拼一个再拼选大的会更大

T2

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct A
{
	int p,q;
}a[1002];
int b,k,r;
bool c(A d,A e)
{
	return d.p*d.q<e.p*e.q;
}
signed main()
{
	cin>>b;
	for(int i=0;i<=b;i++)
	{
		cin>>a[i].p>>a[i].q;
	}
	sort(a+1,a+b+1,c);
	k=a[0].p;
	for(int i=1;i<b;i++)
	{
		r=max(k/a[i].q,r);
		k*=a[i].p;
	}
	cout<<max(k/a[b].q,r);
}
代码
设c为前面的左手值的积
max(c/d.q,c/e.q+d.p/e.q)<max(c/e.q,c/d.q+e.p/d.q)
化简得d.p*d.q<e.p*e.q
原文