题意:给出x, a, y, b, 判断x / a与y / b的大小
思路:数字太大需要大数,计算x * b与y *a的大小,再判断
实现:JAVA大数
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
while(s.hasNext()) {
BigInteger x=s.nextBigInteger();
BigInteger a=s.nextBigInteger();
BigInteger y=s.nextBigInteger();
BigInteger b=s.nextBigInteger();
BigInteger ans=x.multiply(b);
BigInteger ans1=y.multiply(a);
if(ans.compareTo(ans1) < 0)
System.out.println("<");
else if(ans.equals(ans1))
System.out.println("=");
else if(ans.compareTo(ans1) > 0)
System.out.println(">");
}
}
}
E ABBA
题意略
思路:DP,d[i][j]代表第i个A和第j个B有多少种情况,i - j <= n时合法,j - i <= m时合法,所以i - j < n或j - i < m时可以进行转移
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
const int mod = 1e9 + 7;
int d[maxn][maxn];
void add(int &x, int y) {
x += y;
if (x >= mod)
x -= mod;
if (x < 0)
x += mod;
}
int main()
{
int n, m;
while(scanf("%d%d", &n, &m) == 2)
{
for(int i = 0; i <= n + m; i++) for(int j = 0; j <= m + n; j++) d[i][j] = 0;
d[0][0] = 1;
for(int i = 0; i <= n + m; i++)
{
for(int j = 0; j <= m + n; j++)
{
if(i - j < n)add(d[i + 1][j],d[i][j]);
if(j - i < m)add(d[i][j + 1],d[i][j]);
}
}
printf("%d\n", d[n + m][n + m]);
}
return 0;
}
题意:求三角形内一点分割成的三个三角形中最大的面积期望
思路:随即打点后发现期望为大三角形面积的11 / 18,答案需要乘以36
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll x1, y1, x2, y2, x3, y3;
while(~scanf("%lld%lld%lld%lld%lld%lld", &x1, &y1, &x2, &y2, &x3, &y3))
{
ll xa = x2 - x1, xb = x3 - x1;
ll ya = y2 - y1, yb = y3 - y1;
ll ans = 11ll * (xa * yb - ya * xb);
ans = ans >= 0 ? ans : -ans;
printf("%lld\n", ans);
}
return 0;
}
A题是笛卡尔树,在数据结构专题中研究。