从12:00到17:00,是这次网络赛的时间。我与小伙伴们约好在食堂来一场惊心动魄的脑脑裂比赛。从11:00开始准备,吃饭,预热,开始答题。
由于以前了解过ACM,也参加过4C,所以也有一些经验吧。只是第一次,本以为是ccpc,中国的,可以有点中文题目,没想到全是英文题,让我这样的英文渣额。。。不过还好,能读懂一些的!
煎熬中度过,漫度中煎熬。一些题似懂非懂,有思路,但数据范围的卡壳,导致更换思路。。。最后,受大佬启发,完成了一道
a^n+b^n=c^n的题目:
1004 Find Integer
Problem
people in USSS love math very much, and there is a famous math problem .
give you two integers , ,you are required to find integers , such that + .
Input
one line contains one integer ;
next lines contains two integers , ; , ,
Output
print two integers , if , exits; , , ;
else print two integers -1 -1 instead.
Sample Input
1 2 3
Sample Output
4 5
思路:显而易见,对于a^n+b^n=c^n,当N>2时,是没有整数解的(费马大定理),所以问题主要就来到求a^2+b^2=c^2;第一次,我们用O(N)的暴力去解,发现超时,所以第一时间就想到剪枝,寻找其中规律,发现,a*b%6==0;于是,就6个6个找,再用本源勾股在进一步剪枝,a的倍数计算;但发现还是TL了。。。我的天!!!绝望。。。最后呢,有一位大佬说其实有一个公式的,所以,我去研究了一番,发现:
题意:
给出直角三角形的一条边,求另外两条边。无解输出-1.
思路:
1、2无解。
n为偶数,(n * n / 4 – 1) ^ 2 + n * n = (n * n / 4 + 1) ^2
n为奇数,((n * n – 1) / 2) ^ 2 + n * n = ((n * n + 1) / 2) ^ 2
天哪,所以,,,就所以了。最后题目还卡了一下cin与cout的输出时间限制,改成printf与scanf就ok了。
以下是AC代码:
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
int t;
int n,a;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&n,&a);
if(n>2)
{
printf("-1 -1\n");
// cout<<"-1 -1"<<endl;
}
else if(n==2)
{
if(a%2==0)
{
printf("%d %d\n",a*a/4-1,a*a/4+1);
}
else
printf("%d %d\n",(a*a-1)/2,(a*a+1)/2);
}
else if(n==1)
{
printf("%d %d\n",a+1,a+2);
//cout<<a+1<<" "<<a+2<<endl;
}
else
{
printf("-1 -1\n");
}
}
return 0;
}
后面有这样一道题:
1010 YJJ’s Salesman
Problem
YJJ is a salesman who has traveled through western country. YJJ is always on journey. Either is he at the destination, or on the way to destination. One day, he is going to travel from city A to southeastern city B. Let us assume that A is on the rectangle map and B . YJJ is so busy so he never turn back or go twice the same way, he will only move to east, south or southeast, which means, if YJJ is at now , he will only forward to , or . On the rectangle map from to , there are several villages scattering on the map. Villagers will do business deals with salesmen from northwestern, but not northern or western. In mathematical language, this means when there is a village on , only the one who was from to will be able to earn dollars.(YJJ may get different number of dollars from different village.) YJJ has no time to plan the path, can you help him to find maximum of dollars YJJ can get.
Input
The first line of the input contains an integer ,which is the number of test cases.
In each case, the first line of the input contains an integer .The following lines, the -th line contains 3 integers, , which indicate that there is a village on and he can get dollars in that village. The positions of each village is distinct.
Output
The maximum of dollars YJJ can get.
(0,0) ( , ) 109 109
(x,y) (0 ≤ x ≤ ,0 ≤ y ≤ ) 109 109 (x +1,y) (x,y +1) (x +1,y +1) (0,0) ( , ) 109 109
k ( , ) xk yk (1 ≤ ≤ ,1 ≤ ≤ ) xk 109 yk 109 ( −1, −1) xk yk ( , ) xk yk vk
T (1 ≤ T ≤ 10)
N (1 ≤ N ≤ ) 105 N k , , xk yk vk (0 ≤ ≤ ) vk 103 ( , ) xk yk vk
Sample Input
1
3
1 1 1
1 2 2
3 3 1
Sample Output
3
一看这题目就是搜索+dp,思路简单;但看数字,1e9,开个二维数组,绝对爆内存,所以,我想到把二维压成一维去做,不知道有没有错误,代码码到一半,后面再慢慢研究一下,发AC代码。
总的来说,英语还有待加强,做题不够多,自然就GOOD GAME了。。。