# 落絮飞雁的个人网站

## HDOJ1205：吃糖果——简单数学题

Problem Description
HOHO，终于从Speakless手上赢走了所有的糖果，是Gardon吃糖果时有个特殊的癖好，就是不喜欢将一样的糖果放在一起吃，喜欢先吃一种，下一次吃另一种，这样；可是Gardon不知道是否存在一种吃糖果的顺序使得他能把所有糖果都吃完？请你写个程序帮忙计算一下。

Input

sort函数逆序排列的方法就是先定义一个比较函数cmp。然后直接在sort中使用~

AC代码：

```#include
#include
#include
using namespace std;
int cdy;
bool cmp(int a, int b)
{
return a>b;
}
int main()
{
int n, i,num;
_int64 sum;
scanf("%d", &n);
while (n--)
{
sum = 0;
scanf("%d", &num);
for (i = 0; isum+1)
{
printf("Non");
}
else
{
printf("Yesn");
}
}
return 0;
}
```

## HDOJ1061:Rightmost Digit——简单数学题

Problem Description
Given a positive integer N, you should output the most right digit of N^N.

Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000). Output For each test case, you should output the rightmost digit of N^N. Sample Input 2 3 4 Sample Output 7 6 简单题目。打表不解释。直接做会TLE。 代码：

```#include
using namespace std;

int main(){
int n,m;
int a = {{0,0,0,0},{1,1,1,1},{2,4,8,6},{3,9,7,1},{4,6,4,6},{5,5,5,5},{6,6,6,6},{7,9,3,1},{8,4,2,6},{9,1,9,1}};
cin>>m;
while(m–)
cin>>n,cout<=0?n%4-1:3]<
```

## HDOJ1021：Fibonacci Again——简单数学题

Problem Description
There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).

Input
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000). Output Print the word "yes" if 3 divide evenly into F(n). Print the word "no" if not. Sample Input 0 1 2 3 4 5 Sample Output no no yes no no no 判断能否被3整除。可以打表做，简单AC。 代码：

```#include
using namespace std;
int main(){
int n;
while(cin>>n){
if(n%4==2) cout<<"yes"<
```

## HDOJ1008：Elevator——简单数学题

Problem Description
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.

For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.

Input
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.

Output
Print the total time on a single line for each test case.

Sample Input
1 2
3 2 3 1
0

Sample Output
17
41

Author
ZHENG, Jianqiang

3 1 1 1

21

```#include
int main()
{
int n;
while (~scanf("%d", &n)&&n!=0)
{
int f, fi,j, sum;
f = sum = 0;
for (j = 0; j < n; j++)
{
fi = f;
scanf("%d", &f);
if (fi < f)
{
sum += 6 * (f - fi);
}
else if(fi>f)
{
sum += 4 * (fi - f);
}
//if (j!=n-1)注意最后也要停五秒
sum += 5;
}
printf("%dn", sum);
}
return 0;
}
```

## HDOJ2108：Shape of HDU

Problem Description

Input

Output

Sample Input
4
0 0 1 0 1 1 0 1
0

Sample Output
convex

sqrt函数中形参必须为double，但double不能用^2进行乘方，降低了代码可读性。

```#include
#include
#include
int main()
{
int  flag,n,ni;
double a, b, c,cc,arc;
double num;
while(~scanf("%d", &n)&&n!=0)
{
memset(num, 0, sizeof(num));
flag = 0;
for (ni = 0; ni < n; ni++)
{
scanf("%lf%lf", &num[ni], &num[ni]);
}
for (ni = 2; ni < n; ni++)
{
a = sqrt((num[ni - 2] - num[ni - 1])*(num[ni - 2] - num[ni - 1]) + (num[ni - 2] - num[ni - 1])*(num[ni - 2] - num[ni - 1]));
b = sqrt((num[ni - 1] - num[ni])*(num[ni - 1] - num[ni]) + (num[ni - 1] - num[ni])*(num[ni - 1] - num[ni]));
c = sqrt((num[ni - 2] - num[ni])*(num[ni - 2] - num[ni]) + (num[ni - 2] - num[ni])*(num[ni - 2] - num[ni]));
cc = (a*a + b*b - c*c) / (2 * a*b);
arc = acos(cc) * 180 / 3.1415926;
if (arc>(double)180||arc<(double)0)
{
flag = 1;
}
}
a = sqrt((num[ni] - num)*(num[ni] - num) + (num[ni] - num)*(num[ni] - num));
b = sqrt((num - num)*(num - num) + (num - num)*(num - num));
c = sqrt((num[ni] - num)*(num[ni] - num) + (num[ni] - num)*(num[ni] - num));
cc = (a*a + b*b - c*c) / (2 * a*b);
arc = acos(cc) * 180 / 3.1415926;
if (arc>(double)180 || arc<(double)0)
{
flag = 1;
}
if (flag = 0)
{
printf("convexn");
}
if (flag = 1)
{
printf("concaven");
}
}
return 0;
}
```

```#include
#include
struct xy
{
int x;
int y;
};
typedef struct xy xy;
int main()
{
xy num,d,z;
int a, b, c, cc, n, ni;
int flag;
while (~scanf("%d",&n)&&n!=0)
{
flag = 0;
for (ni = 0; ni < n; ni++)
{
scanf("%d%d", &num[ni].x, &num[ni].y);
}
num[ni] = num;
num[ni + 1] = num;
for (ni = 0; ni < n; ni++)
{
d.x = num[ni + 1].x - num[ni].x;
d.y = num[ni + 1].y - num[ni].y;
z.x = num[ni + 2].x - num[ni + 1].x;
z.y = num[ni + 2].y - num[ni + 1].y;
if ((d.x*z.y - d.y*z.x) < 0)
{
flag = 1;
break;
}
}
if (flag == 0)
{
printf("convexn");
}
if (flag == 1)
{
printf("concaven");
}
}
return 0;
}
```

## HDOJ1071：The area

The area

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7807 Accepted Submission(s): 5483

Problem Description
Ignatius bought a land last week, but he didn’t know the area of the land because the land is enclosed by a parabola and a straight line. The picture below shows the area. Now given all the intersectant points shows in the picture, can you tell Ignatius the area of the land?

Note: The point P1 in the picture is the vertex of the parabola.

Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains three intersectant points which shows in the picture, they are given in the order of P1, P2, P3. Each point is described by two floating-point numbers X and Y(0.0<=X,Y<=1000.0).

Output
For each test case, you should output the area of the land, the result should be rounded to 2 decimal places.

Sample Input
2
5.000000 5.000000
0.000000 0.000000
10.000000 0.000000
10.000000 10.000000
1.000000 1.000000
14.000000 8.222222

Sample Output
33.33
40.69

Hint

For float may be not accurate enough, please use double instead of float.

```#include
#include
int main()
{
int n;
double x1,y1,x2,y2,x3,y3;
double a,b,c,k,t;
double area1,area2;
while(~scanf("%d",&n))
while(n--)
{
scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
a=(y2-y1)/pow((x2-x1),2);
b=-2*a*x1;
c=y1-a*x1*x1-b*x1;
k=(y3-y2)/(x3-x2);
t=y3-k*x3;
area1=1.0/3*a*pow(x3,3)+1.0/2*(b-k)*pow(x3,2)+(c-t)*x3;
area2=1.0/3*a*pow(x2,3)+1.0/2*(b-k)*pow(x2,2)+(c-t)*x2;
printf("%.2lfn",area1-area2);
}
return 0;
}
```