一、2401 最大矩形面积 题目链接
Ac代码:
import java.util.*;
public class Main {
public static void main(String []args)
{
Scanner cin = new Scanner(System.in);
int t,i,lr,ud;
node a = new node();
t = cin.nextInt();
while(t-->0)
{
a.l = cin.nextInt();
a.w = cin.nextInt();
a.n = cin.nextInt();
a.INIT();
for(i=2;i<a.n;i++)
{
a.s[i].x = cin.nextInt();
a.s[i].y = cin.nextInt();
}
lr = a.get_lr();
ud = a.get_ud();
System.out.println(Math.max(lr, ud));
}
cin.close();
}
}
class point
{
int x,y;
}
class node
{
int l,w,n;
point s[] = new point[1050];
void INIT()
{
int i;
n = n + 2;
for(i=0;i<n;i++)
s[i] = new point();
s[0].x = 0;
s[0].y = 0;
s[1].x = l;
s[1].y = w;
}
void sortlr()
{
int i,j;
point t = new point();
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(s[j].x>s[j+1].x)
{
t = s[j];
s[j] = s[j+1];
s[j+1] = t;
}
else if(s[j].x==s[j+1].x)
{
if(s[j].y>s[j+1].y)
{
t = s[j];
s[j] = s[j+1];
s[j+1] = t;
}
}
}
}
}
void sortud()
{
int i,j;
point t = new point();
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(s[j].y>s[j+1].y)
{
t = s[j];
s[j] = s[j+1];
s[j+1] = t;
}
else if(s[j].y==s[j+1].y)
{
if(s[j].x>s[j+1].x)
{
t = s[j];
s[j] = s[j+1];
s[j+1] = t;
}
}
}
}
}
int get_lr()
{
int ans = 0,i,j,du,dd;
sortlr();
for(i=0;i<n-1;i++)
{
du = w;
dd = 0;
for(j=i+1;j<n;j++)
{
if(s[i].x!=s[j].x)
{
ans = Math.max(ans, (s[j].x-s[i].x)*(du-dd));
if(s[j].y>s[i].y)
du = Math.min(du, s[j].y);
else
dd = Math.max(dd,s[j].y);
}
}
}
return ans;
}
int get_ud()
{
int ans = 0,i,j,dl,dr;
sortud();
for(i=0;i<n-1;i++)
{
dl = 0;
dr = l;
for(j=i+1;j<n;j++)
{
if(s[i].y!=s[j].y)
{
ans = Math.max(ans, (s[j].y-s[i].y)*(dr-dl));
if(s[j].x>s[i].x)
dr = Math.min(dr, s[j].x);
else
dl = Math.max(dl, s[j].x);
}
}
}
return ans;
}
}
二、2499 数字 题目链接
Ac代码:
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
while ( n!= 0 ){
int a = cin.nextInt();
int b = cin.nextInt();
System.out.println(f(b)-f(a-1));
n--;
}
}
public static int f(int x){
if ( x <= 2 ){
return 0;
}
return x/2-1+((int)Math.sqrt(x)%2==1?0:-1);
}
}
三、2614 This is an YY Problem 题目链接
Ac代码:
import java.util.Scanner;
public class Main {
public static int f(int n, int m, int x)
{
return n * x / m;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t, i, j, n, m, s;
t = in.nextInt();
for(i = 1; i <= t; i++)
{
n = in.nextInt();
m = in.nextInt();
s = 0;
for(j = 1; j <= m - 1; j++)
{
s += (int)f(n, m, j);
}
s = m * n - 2 * s;
System.out.println(s);
}
in.close();
}
}