HDU 6289:
题意:Given an integer n, Chiaki would like to find three positive integers x, y and z such that: n=x+y+z, x∣n, y∣n, z∣n and xyz is maximum.
思路:由于x∣n, y∣n, z∣n 所以只要考虑n%3和n%4的情况就行了。
代码:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
using namespace std;
const int MAXN = 1e5+5;
int main(){
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
if(n%4==0 && n%3!=0){
printf("%lld\n",1ll*n/4*n/4*n/2);
}
else if(n%3==0){
printf("%lld\n",1ll*n/3*n/3*n/3);
}
else puts("-1");
}
return 0;
}
HDU 6300:
题意:给3n个点,任意三点之间不共线,让你将其连线成n个互相不相交的三角形。
思路:由于任意三点不共线,只要按照x轴从小到大排序,然后依次取三个点出来连线,这样取出来的必然是不共线的。
(在二维平面画图可知,在相同的竖线上不会超过两个点,依次连续的三个点连线不会有交线)
代码:
#include<iostream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn=1005;
struct node
{
int x,y,id;
} a[maxn*3];
int n;
bool cmp(node d,node e)
{
if(d.x==e.x)
return d.y<e.y;
return d.x<e.x;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for (int i = 1; i <= 3*n; i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
a[i].id=i;
}
sort(a+1,a+3*n+1,cmp);
for(int i=1; i<=3*n; i+=3)
{
printf("%d %d %d\n",a[i].id,a[i+1].id,a[i+2].id);
}
}
return 0;
}