HDU4716 A. A Computer Graphics Problem

A题目描述

题意:输出手机剩余电量,保证给出的数是10的倍数。

题解:水题,按题意输出即可。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
int main() {
int T,t=,n,m;
for (scanf("%d",&T);t <= T; t++) {
scanf("%d",&n);
n = n/;
m = - n;
printf("Case #%d:\n*------------*\n",t);
for (int i = ; i <= m; i++) printf("|............|\n");
for (int i = ; i <= n; i++) printf("|------------|\n");
printf("*------------*\n");
}
return ;
}

A题代码

HDU4717 B. The Moving Points

B题目描述

题意:告诉你n个点的坐标和他们移动的速度,问你什么时候任意两个点的最大距离最小,以及这个距离是多少。

题解:最大值最小问题我们可以想到二分,点移动可以看成一条线,两条直线的位置关系有平行(重合)和相交,平行(重合)的话他们的距离并不会变,相交的话,这两个点之间的距离可能先变小再变大。我们不能想到这个一个开口向上的二次函数,那么我们三分求解即可得到答案。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int N = + ;
const double esp = 1e-;
int x[N],y[N],vx[N],vy[N];
int n;
double cal(double t) {
double ans = ;
for (int i = ; i < n; i++) {
for (int j = i+; j < n; j++) {
double x1 = x[i] + vx[i]*t;
double y1 = y[i] + vy[i]*t;
double x2 = x[j] + vx[j]*t;
double y2 = y[j] + vy[j]*t;
ans = max(ans,sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
}
return ans;
}
int main() {
int T,cas = ;
for (scanf("%d",&T);cas <= T; cas++) {
scanf("%d",&n);
for (int i = ; i < n; i++)
scanf("%d%d%d%d",&x[i],&y[i],&vx[i],&vy[i]);
double t,ans,l = , r = 1e10;
while (r - l > esp) {
double mid = (l+r)/;
double mmid = (mid + r)/;
double l1 = cal(mid);
double l2 = cal(mmid);
if (l2 - l1 > esp) r = mmid-esp;
else l = mid +esp;
}
t = l;
ans = cal(t);
printf("Case #%d: %.2f %.2f\n",cas,t,ans);
}
return ;
}

B题代码

HDU4720 E. Naive and Silly Muggles

Three wizards are doing a experiment. To avoid from bothering, a special magic is set around them. The magic forms a circle, which covers those three wizards, in other words, all of them are inside or on the border of the circle. And due to save the magic power, circle's area should as smaller as it could be.
Naive and silly "muggles"(who have no talents in magic) should absolutely not get into the circle, nor even on its border, or they will be in danger.
Given the position of a muggle, is he safe, or in serious danger? Input
The first line has a number T (T <= ) , indicating the number of test cases.
For each test case there are four lines. Three lines come each with two integers x i and y i (|x i, y i| <= ), indicating the three wizards' positions. Then a single line with two numbers q x and q y (|q x, q y| <= 10), indicating the muggle's position. Output
For test case X, output "Case #X: " first, then output "Danger" or "Safe". Sample Input -0.5 -0.6 -1.5 Sample Output
Case #: Danger
Case #: Safe
Case #: Safe

E题目描述

题意:给出三个巫师的坐标A(x1,y2)、B(x2,y2)、C(x3,y3)和一个非魔法界的人的坐标D,如果坐标D在包含坐标ABC组成的最小的圆里面的话输出Danger,否则输出Safe。

题解:但ABC在一条直线上或者ABC组成的三角形是钝角三角形时,最小圆的圆心为距离最远的两个点的中心。否则的话,我们可以通过公式算出圆心坐标:

  x=((y2*y2-y1*y1+x2*x2-x1*x1)*(y3-y1)-(y3*y3-y1*y1+x3*x3-x1*x1)*(y2-y1))/(2*((y3-y1)*(x2-x1)-(y2-y1)*(x3-x1)));
       y=(y2*y2-y1*y1+x2*x2-x1*x1-2*x2*x+2*x1*x)/(2*(y2-y1));

我们要注意y2不能等于y1所以我们在计算之前要判断一下A和B的纵坐标是否相同,如果相同的话将A和C的坐标互换一下。(因为此时ABC一定能组成三角形,所以最多两个点纵坐标相同)。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int N = 1e5 + ;
struct Point{
double x,y;
}a[],p,b[],o;
double dis(Point i,Point j) {
return (i.x-j.x)*(i.x-j.x)+(i.y-j.y)*(i.y-j.y);
}
int main() {
int T,t=;
for (scanf("%d",&T);t <= T; t++) {
for (int i = ; i < ; i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
scanf("%lf%lf",&p.x,&p.y);
double ma = ,sum = ;
int u,v,cnt = ;
double len[];
for (int i = ; i < ; i++)
for (int j = ; j < i; j++) {
len[cnt++] = dis(a[i],a[j]);
sum += len[cnt-];
if (ma < len[cnt-]) {
ma = len[cnt-]; u = i; v = j;
}
}
b[] = a[u],b[] = a[v];
bool fg = false;
if ((a[].x-a[].x)*(a[].y-a[].y) == (a[].x-a[].x)*(a[].y-a[].y)) {
o.x = (b[].x+b[].x)/;
o.y = (b[].y+b[].y)/;
double l1 = dis(o,b[]);
double l2 = dis(o,p);
if (l2 - l1 < 1e-) fg = true;
}else {
if (sum - ma < ma) {//钝角
o.x = (b[].x+b[].x)/;
o.y = (b[].y+b[].y)/;
double l1 = dis(o,b[]);
double l2 = dis(o,p);
if (l2 - l1 < 1e-) fg = true;
}else {
if (a[].y == a[].y) swap(a[],a[]);
double x = p.x;
double x1 = a[].x,y1 = a[].y;
double x2 = a[].x,y2 = a[].y;
double x3 = a[].x,y3 = a[].y;
o.x=((y2*y2-y1*y1+x2*x2-x1*x1)*(y3-y1)-(y3*y3-y1*y1+x3*x3-x1*x1)*(y2-y1))/(*((y3-y1)*(x2-x1)-(y2-y1)*(x3-x1)));
o.y=(y2*y2-y1*y1+x2*x2-x1*x1-*x2*x+*x1*x)/(*(y2-y1));
double l1 = dis(o,a[]);
double l2 = dis(o,p);
if (l2 - l1 < 1e-) fg = true;
}
}
printf("Case #%d: %s\n", t,fg?"Danger":"Safe");
}
return ;
}

HDU4722 G. Good Numbers

If we sum up every digit of a number and the result can be exactly divided by , we say this number is a good number.
You are required to count the number of good numbers in the range from A to B, inclusive. Input
The first line has a number T (T <= ) , indicating the number of test cases.
Each test case comes with a single line with two numbers A and B ( <= A <= B <= ^). Output
For test case X, output "Case #X: " first, then output the number of good numbers in a single line. Sample Input Sample Output
Case #:
Case #: Hint
The answer maybe very large, we recommend you to use long long instead of int.

G题目描述

题意:给你两个数A,B(0 <= A <= B <= 1018),问A到B之间(包括A,B)有多少个数满足它的每一位数之和是10的倍数。

题解:通过打表我们发现0~10有1个,0~100有10个,0~1000有100个,所以如果一个数x是10的倍数,那么0~x就有x/10个满足条件的数。那么如果这个数不是10的倍数呢?我们可以先把前几位求和,然后从0到x%10枚举有几个数满足条件,在加上x/10,就是0~x中满足条件的数的个数。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int N = 1e5 + ;
ll cal(ll x) {
ll y = x/*,z = x%,sum = , ans = ;
while (y) {
sum += y%; y /= ;
}
for (ll i = ; i <= z; i++)
if ( (sum + i)% == ) ans++;
return ans;
}
ll work(ll x) {
return x/+cal(x);
}
int main() {
int T,t=;
for (scanf("%d",&T);t <= T; t++) {
ll n,m;
scanf("%lld%lld",&n,&m);
printf("Case #%d: %lld\n", t, work(m)-work(n-));
}
return ;
}

G题代码

HDU4726 K.Kia's Calculation

Doctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so careless and alway forget to carry a number when the sum of two digits exceeds . For example, when she calculates +, she will get , and for +, she will get . Ghee is angry about this, and makes a hard problem for her to solve:
Now Kia has two integers A and B, she can shuffle the digits in each number as she like, but leading zeros are not allowed. That is to say, for A = , she can rearrange the number as , or , or many other, but is not allowed.
After she shuffles A and B, she will add them together, in her own way. And what will be the maximum possible sum of A "+" B ? Input
The rst line has a number T (T <= ) , indicating the number of test cases.
For each test case there are two lines. First line has the number A, and the second line has the number B.
Both A and B will have same number of digits, which is no larger than , and without leading zeros. Output
For test case X, output "Case #X: " first, then output the maximum possible sum without leading zeros. Sample Input Sample Output
Case #:

K题目描述

题意:给你两个数A,B,你可以将它们重新排列(但不能有前导零),例如A=3036,你可以把它看成6330也可以把它看成3360,但不能看成0336。 然后再将它们每一位对应做不进位的加法(保证位数相同),问结果进行加法计算之后的结果最大是多少(不含前导零)。

题解:拿两个数组分别记录A和B中0~9的数量,然后贪心。

   注意最高位数不能有0。

   还要注意最高位加起来%10==0的情况。

  PS:做题时以为是A、B大小不超过10^6,结果是位数不超过10^6,结果一直WA。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int N = 1e6 + ;
char s1[N],s2[N];
int a[N],b[N];
int main() {
int T,t=;
for (scanf("%d",&T);t <= T; t++) {
scanf("%s%s",s1,s2);
printf("Case #%d: ", t);
int num1[]={},num2[]={};
int len = strlen(s1);
for (int i = ; i < len; i++) {
a[i] = s1[i]-'';
b[i] = s2[i]-'';
num1[a[i]]++;
num2[b[i]]++;
}
int x = ;
pair<int,int> id;
id.first = id.second = ;
for (int i = ; i <= ; i++) {
for (int j = ;num1[i]> && j <= ; j++) {
if (num2[j] > && (i+j)% >= x) {
x = (i+j)%;
id.first = i;
id.second = j;
if(x==) break;
}
}
}
bool fg = false;
if (x>) fg = true;
if (fg) printf("%d",x);
num1[id.first]--;
num2[id.second]--;
for (int k = ; k < len; k++) {
x = ;
for (int i = ; i < ; i++) {
for (int j = ;num1[i]> && j < ; j++) {
if (num2[j]> && (i+j)% >= x) {
x = (i+j)%;
id.first = i;
id.second = j;
if (x == ) break;
}
}
}
if (!fg && x>) fg = true;
if (fg) printf("%d",x);
num1[id.first]--;
num2[id.second]--;
}
if (!fg) printf("");
printf("\n");
}
return ;
}

HDU4727 L. The Number Off of FFF

X soldiers from the famous " *FFF* army" is standing in a line, from left to right.
You, as the captain of *FFF*, decides to have a "number off", that is, each soldier, from left to right, calls out a number. The first soldier should call "One", each other soldier should call the number next to the number called out by the soldier on his left side. If every soldier has done it right, they will call out the numbers from to X, one by one, from left to right.
Now we have a continuous part from the original line. There are N soldiers in the part. So in another word, we have the soldiers whose id are between A and A+N- ( <= A <= A+N- <= X). However, we don't know the exactly value of A, but we are sure the soldiers stands continuously in the original line, from left to right.
We are sure among those N soldiers, exactly one soldier has made a mistake. Your task is to find that soldier. Input
The rst line has a number T (T <= ) , indicating the number of test cases.
For each test case there are two lines. First line has the number N, and the second line has N numbers, as described above. ( <= N <= )
It guaranteed that there is exactly one soldier who has made the mistake. Output
For test case X, output in the form of "Case #X: L", L here means the position of soldier among the N soldiers counted from left to right based on . Sample Input Sample Output
Case #:
Case #:

L题目描述

题意:给你一个长度为n的序列,已知里面的元素依次应该为x~x+n,但是里面有且仅有一个元素错了,找出这个元素的下标(下标从1开始)。

题解:一个for循环判断当前元素是否等于前一个元素+1,不同的话就代表当前元素错了。但是要注意,如果错了的元素是第二个的话,可能是第一个错了,需要判断一下第2个元素+1是否等于第3个元素,是的话就是1错了。还要注意的一个点是如果整个序列都是对的,那么输出1,因为题目说了有1个错了。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int N = 1e5 + ;
int a[N];
int main() {
int T,t=;
for (scanf("%d",&T);t <= T; t++) {
int n,ans = ;
scanf("%d",&n);
for (int i = ; i <= n; i++) scanf("%d",&a[i]);
for (int i = ; i <= n; i++)
if (a[i] != a[i-]+) {
ans = i;
break;
}
if (ans == && a[]+ == a[]) ans = ;
printf("Case #%d: %d\n", t, ans);
}
return ;
}

2013 ACM/ICPC Asia Regional Online —— Warmup2 ABEGKL的更多相关文章

  1. 2013 ACM/ICPC Asia Regional Online —— Warmup2

    HDU 4716 A Computer Graphics Problem 水题.略 HDU 4717 The Moving Points 题目:给出n个点的起始位置以及速度矢量,问任意一个时刻使得最远 ...

  2. HDU4726——Kia's Calculation——2013 ACM/ICPC Asia Regional Online —— Warmup2

    题目的意思是给你两个数字(多达10^6位) 做加法,但是有一点,没有进位(进位不算,相当于这一位相加后对10取模) 你可以任意排列两个数字中的每一位,但是不能是0开头. 现在题目要求以这种不进位的算法 ...

  3. HDU4722——Good Numbers——2013 ACM/ICPC Asia Regional Online —— Warmup2

    今天比赛做得一个数位dp. 首先声明这个题目在数位dp中间绝对是赤裸裸的水题.毫无技巧可言. 题目的意思是个你a和b,要求出在a和b中间有多少个数满足数位上各个数字的和为10的倍数. 显然定义一个二维 ...

  4. HDU 4717 The Moving Points(三分法)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)

    Description There are N points in total. Every point moves in certain direction and certain speed. W ...

  5. HDU 4719 Oh My Holy FFF(DP+线段树)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)

    Description N soldiers from the famous "*FFF* army" is standing in a line, from left to ri ...

  6. HDU 4722 Good Numbers(位数DP)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)

    Description If we sum up every digit of a number and the result can be exactly divided by 10, we say ...

  7. HDU 4725 The Shortest Path in Nya Graph(最短路径)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)

    Description This is a very easy problem, your task is just calculate el camino mas corto en un grafi ...

  8. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  9. hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...

随机推荐

  1. C#面向对象--命名空间与类库

    1.命名空间 在源代码文件开头使用using语句引用 命名空间,就可以直接使用其中的类而不再需要指明其所属的命名空间. .NET Framework使用命名空间来管理所有的类. 类的修饰符:   pu ...

  2. HDU1711 Number Sequence 题解 KMP算法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 题目大意:最基础的字符串匹配,只不过这里用整数数组代替了字符串. 给你两个数组 \(a[1..N ...

  3. Codeforces Round #177 (Div. 1 + Div. 2)

    A. Polo the Penguin and Segments 模拟. B. Polo the Penguin and Matrix 每个数字模d余数必须一样. 枚举结果,可计算操作次数,取最小. ...

  4. 阿里巴巴Java编程规范考试

    阿里巴巴Java编程规范考试 今天在阿里云官网把阿里巴巴Java编程规范认证考试考过了, 写下这篇文章总结一下考试中需要注意的知识点, 主体内容还是要直接看规范: 编程规约 异常日志 单元测试 安全规 ...

  5. Notice: Use of undefined constant - assumed ' '

    昨天看手册的时候有两个范例,懒得写了,直接复制,测试一下,结果报Notice; 反复检查无果,最后, 手动敲了一遍,居然正常了,汗.... 总结:偷懒害人

  6. H3C 静态路由配置

  7. linux 分配和释放设备编号

    在建立一个字符驱动时你的驱动需要做的第一件事是获取一个或多个设备编号来使用. 为 此目的的必要的函数是 register_chrdev_region, 在 <linux/fs.h>中声明: ...

  8. C# 多线程的等待所有线程结束

      //前台线程和后台线程唯一区别就是:应用程序必须运行完所有的前台线程才可以退出://而对于后台线程,应用程序则可以不考虑其是否已经运行完毕而直接退出,//所有的后台线程在应用程序退出时都会自动结束 ...

  9. CF1209

    CF1209 A B 水题不管 C 因为要求最终整个序列是要单调的 所以我们就考虑枚举断点$x$ 之后把$<x$的数放到第一个集合 把$> x$的数放到第二个集合 至于$=x$的数 他能放 ...

  10. 【21.00%】【vijos P1018】智破连环阵

    描述 B国在耗资百亿元之后终于研究出了新式武器--连环阵(Zenith Protected Linked Hybrid Zone).传说中,连环阵是一种永不停滞的自发性智能武器.但经过A国间谍的侦察发 ...