HDU 6225 Little Boxes

题意

计算四个整数的和

解题思路

使用Java大整数

 import java.math.BigInteger;
import java.util.Scanner; /**
*
* @author reqaw
*/
public class Main { /**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T;
T = in.nextInt();
while(T-- > 0) {
BigInteger a = in.nextBigInteger();
BigInteger b = in.nextBigInteger();
BigInteger c = in.nextBigInteger();
BigInteger d = in.nextBigInteger();
System.out.println(a.add(b).add(c).add(d));
}
} }

HDU 6227 Rabbits

题意

n只兔子排在一条直线上,每只兔子都有一个坐标,最外边的兔子可以跳到两只兔子中间的空位上,每跳一次称为一次计数,问最多能够玩几次。

解题思路

从第二只兔子开始计算相邻的空位有几个,正着一遍,倒着一遍,取最大值即可。

 #include <cstdio>

 const int maxn =  + ;
int a[maxn];
int main()
{
int T, n;
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i = ; i < n; i++) {
scanf("%d", &a[i]);
}
int s1 = ;
for(int i = ; i < n - ; i++) {
s1 += a[i + ] - a[i] - ;
}
int s2 = ;
for(int i = n - ; i > ; i--) {
s2 += a[i] - a[i - ] - ;
}
printf("%d\n", s1 > s2 ? s1 : s2);
}
return ;
}

HDU 6222 Heron and His Triangle

题意

先定义了一个H三角形,它的三条边由连续的三个整数构成,即t-1, t , t+1,并且它的面积是一个整数。给出一个整数n(最大可能是10^30),问满足t>=n的最小t是多少。

解题思路

先暴力打出前几个满足条件的t,仔细观察发现满足一个规律,res[i] = res[i - 1] * 4 - res[i - 2];由于数字很大,使用Java大数。

 /*先暴力出前几项*/
#include <cstdio>
#include <cmath>
typedef unsigned long long ull;
int main()
{
for(ull t = ; t <= ; t++) {
ull a = t - ;
ull b = t;
ull c = t + ;
ull p = (a + b + c) / ;
ull k = p * (p - a) * (p - b) * (p - c);
if((ull)sqrt(k) * (ull)sqrt(k) == k) {
printf("%lld\n", t);
}
}
return ;
}

找到规律后打表

 import java.math.BigInteger;
import java.util.Scanner; /**
*
* @author reqaw
*/
public class Main { /**
* @param args the command line arguments
*/
public static void main(String[] args) {
BigInteger res[] = new BigInteger[100];
res[0] = BigInteger.valueOf(4L);
res[1] = BigInteger.valueOf(14L);
for(int i = 2; i < 100; i++) {
res[i] = res[i - 1].multiply(res[0]).subtract(res[i - 2]);
//System.out.println(res[i]);
}
Scanner cin = new Scanner(System.in);
int T = cin.nextInt();
while(T-- > 0) {
BigInteger n = cin.nextBigInteger();
for(int i = 0; i < 100; i++) {
if(res[i].compareTo(n) >= 0) {
System.out.println(res[i]);
break;
}
}
}
} }

HDU 6219 Empty Convex Polygons

题意

给出n个点,求由这n个点组成的最大空凸包的面积是多少。

解题思路

使用求解最大空凸包的模板,基本思想是穷举所 要求解的空凸包的最低最左点(先保证最低,再保证最左)。

  对于每一个穷举到的点v,进行动态规划,用opt[i][j]表示符合如下限制的凸包中的最大面积:

  在凸包上v顺时针过来第一个点是i,并且i顺时针过来第一个点k不在i->j的左手域(k 可以等于 j)。

 #include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std; const int maxn = ;
const double zero = 1e-; struct Vector {
double x, y;
}; inline Vector operator - (Vector a, Vector b) {
Vector c;
c.x = a.x - b.x;
c.y = a.y - b.y;
return c;
}
inline double Sqr(double a) {
return a * a;
}
inline int Sign(double a) {
if(fabs(a) <= zero) return ;
return a < ? - : ;
}
inline bool operator < (Vector a, Vector b) {
return Sign(b.y - a.y) > || Sign(b.y - a.y) == && Sign(b.x - a.x) > ;
}
inline double Max(double a, double b) {
return a > b ? a : b;
}
inline double Length(Vector a) {
return sqrt(Sqr(a.x) + Sqr(a.y));
}
inline double Cross(Vector a, Vector b) {
return a.x * b.y - a.y * b.x;
} Vector dot[maxn], List[maxn];
double opt[maxn][maxn];
int seq[maxn];
int n, len;
double ans; bool Compare(Vector a, Vector b) {
int temp = Sign(Cross(a, b));
if(temp != ) return temp > ;
temp = Sign(Length(b) - Length(a));
return temp > ;
} void Solve(int vv) {
int t, i, j, _len;
for(i = len = ; i < n; i++) {
if(dot[vv] < dot[i])
List[len++] = dot[i] - dot[vv];
}
for(i = ; i < len; i++) {
for(j = ; j < len; j++) {
opt[i][j] = ;
}
}
sort(List, List + len, Compare);
double v;
for(t = ; t < len; t++) {
_len = ;
for(i = t - ; i >= && Sign(Cross(List[t], List[i])) == ; i--); while(i >= ) {
v = Cross(List[i], List[t]) / ;
seq[_len++] = i;
for(j = i - ; j >= && Sign(Cross(List[i] - List[t],
List[j] - List[t])) > ; j--);
if(j >= )
v += opt[i][j];
ans = Max(ans, v);
opt[t][i] = v;
i = j;
}
for(i = _len - ; i >= ; i--) {
opt[t][seq[i]] = Max(opt[t][seq[i]], opt[t][seq[i + ]]);
}
}
} int i;
double Empty() {
ans = ;
for(i = ; i < n; i++) {
Solve(i);
}
return ans;
} int main()
{
int T;
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(i = ; i < n; i++) {
scanf("%lf%lf", &dot[i].x, &dot[i].y);
}
printf("%.1lf\n", Empty());
}
return ;
}

HDU 6228 Tree

题意

相对题意不太好理解,给出n个顶点的无根树,也即无向图,k种颜色,问将每一个顶点染成一种颜色,然后将同种颜色的顶点用最少的边连起来(以及每两点间是最短路)组成E,有k中颜色,也就是每一种染色方案有E1,E2...Ek,问它们的交集(边的交集)最大是多少

解题思路

关键是题意的转化,可以想象的是在一个无根树中,给每个点染上k种颜色中的一种,然后将颜色相同的点使用最短路连接起来,连接起来的边算刷一遍,最后求的就是所有的边中,次数被刷k次及其以上的边最多有多少条。

具体实现时,先明白如果该边满足条件,那么两端的点都需要大于k个才行,我们使用深搜计算每个节点的子孙数即可。

 #include <cstdio>
#include <vector>
using namespace std; const int maxn = + ;
int n, k;
int ans;
vector<int> e[maxn];
int num[maxn]; void dfs(int u, int pre) {
num[u] = ;
int eus = e[u].size();
for(int i = ; i < eus; i++) {
int v = e[u][i];
if(v == pre) continue;
dfs(v, u); num[u] += num[v];//递归返回时将u的子孙结点数加上
if(num[v] >= k && n - num[v] >= k) ans++;
}
} int main()
{
int T;
scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &k);
for(int i = ; i < maxn; i++) {
e[i].clear();
}
for(int i = ; i < n - ; i++) {
int u, v;
scanf("%d%d", &u, &v);
e[u].push_back(v);
e[v].push_back(u);
}
ans = ;
dfs(, -);
printf("%d\n", ans);
}
return ;
}

2017ACM/ICPC亚洲区沈阳站(部分解题报告)的更多相关文章

  1. HDU 6227.Rabbits-规律 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))

    Rabbits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  2. HDU 6225.Little Boxes-大数加法 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))

    整理代码... Little Boxes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/O ...

  3. 2017ACM/ICPC亚洲区沈阳站-重现赛

    HDU 6222 Heron and His Triangle 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6222 思路: 打表找规律+大数运算 首先我 ...

  4. 2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)

    Little Boxes Problem Description Little boxes on the hillside.Little boxes made of ticky-tacky.Littl ...

  5. 2017ACM/ICPC亚洲区沈阳站 C Hdu-6219 Empty Convex Polygons 计算几何 最大空凸包

    题面 题意:给你一堆点,求一个最大面积的空凸包,里面没有点. 题解:红书板子,照抄完事,因为题目给的都是整点,所以最后答案一定是.5或者.0结尾,不用对答案多做处理 #include<bits/ ...

  6. HDU 5950 Recursive sequence 【递推+矩阵快速幂】 (2016ACM/ICPC亚洲区沈阳站)

    Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  7. HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  8. HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)

    Thickest Burger Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  9. HDU 5949 Relative atomic mass 【模拟】 (2016ACM/ICPC亚洲区沈阳站)

    Relative atomic mass Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

随机推荐

  1. linux debian 9 / centos 7配置postgresSQL数据库

    #读者注意:本文可以选择不看解释,直接执行每段的0中的代码 (〇):一些概念(可以跳过直接使用(一)0的代码) 1. 客户端:psql.postgreSQL的命令行客户端程序,在终端输入psql进入p ...

  2. ABP 权限拦截 第二篇

    由于访问人数过多,我今天从新整理一下ABP权限认证机制,帮助大家更容易读懂 1.Abp 的权限拦截主要通过过滤器,    public class AbpAuthorizationFilter : I ...

  3. JavaScript 排序算法

    排序也是在程序中经常用到的算法.无论使用冒泡排序还是快速排序,排序的核心是比较两个元素的大小.如果是数字,我们可以直接比较,但如果是字符串或者两个对象呢?直接比较数学上的大小是没有意义的,因此,比较的 ...

  4. ABP框架系列之二:(Entity Framework Core-实体核心框架)

    Introduction(介绍) Abp.EntityFrameworkCore nuget package is used to integrate to Entity Framework (EF) ...

  5. s11.9 sar:收集系统信息

    功能说明: 通过sar命令,可以全面地获取系统的CPU.运行队列.磁盘I/O.分页(交换区).内存.CPU中断和网络等性能数据. 语法格式 sar  option interval count sar ...

  6. sshpass 使用方法

    首先下载sshpass并且安装 $ tar -zxvf sshpass-1.06.tar.gz $ cd sshpass-1.06 $ ./configure --prefix=/usr/local/ ...

  7. PowerShell 命令行调试指引(转)

    How to manage a debugging session Before you start debugging, you must set one or more breakpoints. ...

  8. [预打印]使用vbs给PPT(包括公式)去背景

    原先博客放弃使用,几篇文章搬运过来 在 视图—>宏 内新建宏 '终极版 Sub ReColor() Dim sld As Slide Dim sh As Shape For Each sld I ...

  9. Qt中的CSS配置(QDarkStyleSheet)

    QDarkStylesheet gihub地址 https://github.com/ColinDuquesnoy/QDarkStyleSheet

  10. 131.leetcode-Palindrome Partitioning

    解法一. class Solution { public: vector<vector<string>> partition(string s) { vector<vec ...