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. Gym - 100781G-Goblin Garden Guards

    题目链接:https://nanti.jisuanke.com/t/28882 解题思路:单纯的判断点是否在圆内,一一遍历圆外切正方形内的点即可,注意,该题要建个结构体数组存每个地精的位置,再bool ...

  2. java多线程系列12 ConcurrentHashMap CopyOnWriteArrayList 简介

    我们知道 ,hashmap 和 arraylist 是线程不安全的 在多线程环境下有数据安全问题, 当然 我们可以通过Collections的一些方法把他们变成线程安全的, Collections.s ...

  3. win7访问局域网总提示用户名密码错误解决方案

    win7访问局域网总提示用户名密码错误解决方案 1.点击开始-在搜索栏输入:secpol.msc(或者直接按下win+r键,输入secpol.msc),打开本地安全策略. 2.找到“安全设置”的“本地 ...

  4. ORA-12514: TNS:监听程序当前无法识别连接描述符中请

    若Oracle出现“监听程序当前无法识别连接描述符中请求的服务”这个错误可以按照以下方法解决: 可以通过这个路径找到一个文本文件: oracle\product\10.2.0\db_1\NETWORK ...

  5. Docker基础-使用Dockerfile创建镜像

    1.基本结构 Dockerfile由一行行命令语句组成,并支持以#开头的注释行.例如: # This dockerfile uses the ubuntu image # VERSION 2 - ED ...

  6. linq转载

    在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有关的语言特性 1.隐式类型 (1)源起 在隐式类型出现之前, 我们在声明一个变量的时候, 总是要为一个变量指定他的类型 甚至在fore ...

  7. 背水一战 Windows 10 (90) - 文件系统: 获取 Package 中的文件, 可移动存储中的文件操作, “库”管理

    [源码下载] 背水一战 Windows 10 (90) - 文件系统: 获取 Package 中的文件, 可移动存储中的文件操作, “库”管理 作者:webabcd 介绍背水一战 Windows 10 ...

  8. 背水一战 Windows 10 (75) - 控件(控件基类): FrameworkElement - 基础知识, 相关事件, HorizontalAlignment, VerticalAlignment

    [源码下载] 背水一战 Windows 10 (75) - 控件(控件基类): FrameworkElement - 基础知识, 相关事件, HorizontalAlignment, Vertical ...

  9. JVM自动内存管理机制——Java内存区域(下)

    一.虚拟机参数配置 在上一篇<Java自动内存管理机制——Java内存区域(上)>中介绍了有关的基础知识,这一篇主要是通过一些示例来了解有关虚拟机参数的配置. 1.Java堆参数设置 a) ...

  10. C#基础-gc算法

    众所周知,c++是需要程序员手动管理内存的,然而手动释放内存很容易被程序员遗漏,从而导致资源浪费或内存泄露.为解决这个问题,垃圾回收器诞生了,代替程序员自动管理内存的释放.至于gc算法则是垃圾回收器清 ...