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. zeromq学习记录(八)负载均衡 附ZMQ_ROUTER的流程分析

    /************************************************************** 技术博客 http://www.cnblogs.com/itdef/   ...

  2. Python3个人学习笔记--每天一点一滴成长!

    简单的while循环:输入一个数字,while获取该数字,并输出该数字. 例子:猜幸运数字是多少? lucky_num = int(input("number:")) a = 0 ...

  3. save to project-level dictionary? save to application-level dictionary?

    通过静态代码分析工具lint在Spelling typo得到save to project-level dictionary? save to application-level dictionary ...

  4. docker-compose安装redis-sentinel集群(1主+2副+2哨兵)

    前提:本试验环境已经提前安装了docker和docker-compose 说明:本次部署是单机伪集群,想要部署真正的集群,需要将秒个主件拆分到各个机器上去部署,只修改ip地址 1.下载redis的相关 ...

  5. 几种String对象方法的区别

    1.在String对象方法中,发现.slice()方法和.substring()方法的作用几乎相同,都是根据起始索引返回截取得到的字符串.经过查阅资料和实测得到区别: 正常情况下索引都为正值,返回值为 ...

  6. [转]kaldi特征和模型空间转换

    转:http://blog.csdn.net/shmilyforyq/article/details/76807431 博主话:这篇博客是对kaldi官网中Feature and model-spac ...

  7. 42_并发编程-JionableQueue

    一.生产者消费者模型   在线程世界里,生产者就是生产数据的线程,消费者就是消费数据的线程.在多线程开发当中,如果生产者处理速度很快,而消费者处理速度很慢,那么生产者就必须等待消费者处理完,才能继续生 ...

  8. iOS 抓包

    通过tcpdump对iOS进行流量分析(无需越狱 iOS Packet Tracing 将 iOS 设备通过 USB 连接到 Mac 打开 terminal rvictl -s $UDID 运行 tc ...

  9. 深圳scala-meetup-20180902(1)- Monadic 编程风格

    刚完成了9月份深圳scala-meetup,趁刮台风有空,把我在meetup里的分享在这里发表一下.我这次的分享主要分三个主题:“Monadic编程风格“.”Future vs Task and Re ...

  10. 使用 PLSQL 提示动态执行表不可访问,本会话的自动统计被禁止

    使用PLSQL,第一次执行表的select操作的时候,提示"动态执行表不可访问,本会话的自动统计被禁止",如上图: 这种问题,一看就是当前连接用户没有对sys用户下的表v$sess ...