HDOJ1205:吃糖果——简单数学题

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

Input
第一行有一个整数T,接下来T组数据,每组数据占2行,第一行是一个整数N(0注意大数组要放在main()函数之外,否则RE。sum 必须用_int64开才行,long long int 会导致Runtime Error(OJ傲娇?!)
sort函数逆序排列的方法就是先定义一个比较函数cmp。然后直接在sort中使用~
悲剧的RE了无数次……
AC代码:

#include
#include
#include
using namespace std;
int cdy[1000001];
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 #include using namespace std; int main(){ int n,m; int a[10][4] = {{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]

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

别人问的一道题目,没什么好说的。要注意即便是相同楼层也要停5s才行。

样例:

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 f)
			{
				sum += 4 * (fi - f);
			}
			//if (j!=n-1)注意最后也要停五秒
				sum += 5;
		}
		printf("%dn", sum);
	}
	return 0;
}

临近期末,心浮气躁。来点水题降降火~

HDOJ2108:Shape of HDU

Problem Description
话说上回讲到海东集团推选老总的事情,最终的结果是XHD以微弱优势当选,从此以后,“徐队”的称呼逐渐被“徐总”所取代,海东集团(HDU)也算是名副其实了。
创业是需要地盘的,HDU向钱江肉丝高新技术开发区申请一块用地,很快得到了批复,据说这是因为他们公司研发的“海东牌”老鼠药科技含量很高,预期将占全球一半以上的市场。政府划拨的这块用地是一个多边形,为了描述它,我们用逆时针方向的顶点序列来表示,我们很想了解这块地的基本情况,现在请你编程判断HDU的用地是凸多边形还是凹多边形呢?

 

Input
输入包含多组测试数据,每组数据占2行,首先一行是一个整数n,表示多边形顶点的个数,然后一行是2×n个整数,表示逆时针顺序的n个顶点的坐标(xi,yi),n为0的时候结束输入。

 

Output
对于每个测试实例,如果地块的形状为凸多边形,请输出“convex”,否则输出”concave”,每个实例的输出占一行。

 

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

 

Sample Output
convex

 

采用的方法是三角函数求内角度数,判断角是否超过180.

问题:

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

忘记判断最后一点与初始两点的角度。

还是WA:

#include
#include
#include
int main()
{
	int  flag,n,ni;
	double a, b, c,cc,arc;
	double num[2][10000];
	while(~scanf("%d", &n)&&n!=0)
	{
		memset(num, 0, sizeof(num));
		flag = 0;
		for (ni = 0; ni < n; ni++)
		{
			scanf("%lf%lf", &num[0][ni], &num[1][ni]);
		}
		for (ni = 2; ni < n; ni++)
		{
			a = sqrt((num[0][ni - 2] - num[0][ni - 1])*(num[0][ni - 2] - num[0][ni - 1]) + (num[1][ni - 2] - num[1][ni - 1])*(num[1][ni - 2] - num[1][ni - 1]));
			b = sqrt((num[0][ni - 1] - num[0][ni])*(num[0][ni - 1] - num[0][ni]) + (num[1][ni - 1] - num[1][ni])*(num[1][ni - 1] - num[1][ni]));
			c = sqrt((num[0][ni - 2] - num[0][ni])*(num[0][ni - 2] - num[0][ni]) + (num[1][ni - 2] - num[1][ni])*(num[1][ni - 2] - num[1][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[0][ni] - num[0][0])*(num[0][ni] - num[0][0]) + (num[1][ni] - num[1][0])*(num[1][ni] - num[1][0]));
		b = sqrt((num[0][0] - num[0][1])*(num[0][0] - num[0][1]) + (num[1][0] - num[1][1])*(num[1][0] - num[1][1]));
		c = sqrt((num[0][ni] - num[0][1])*(num[0][ni] - num[0][1]) + (num[1][ni] - num[1][1])*(num[1][ni] - num[1][1]));
		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;
}

 


更新下AC代码:

思路是判断相邻两条边的斜率,如果第二条边斜率小于第一条边,则为凹。

 

#include
#include
struct xy
{
    int x;
    int y;
};
typedef struct xy xy;
int main()
{
    xy num[10001],d,z;
    int a, b, c, cc, n, ni;
    int flag;
    while (~scanf("%d",&n)&&n!=0)
    {
        flag = 0;
        for (ni = 0; ni 

 

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;
}