题目链接:Contest Problem List http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=721
http://acm.hdu.edu.cn/search.php?field=problem&key=BestCoder+Round+%2386&source=1&searchmode=source
Problem 1001 Price List
Accept: 0 Submit: 0
Time Limit: 2000/1000 MS (Java/Others) Memory Limit : 262144/131072 K (Java/Others)
Problem Description
Input
Output
For each test case, print a line with m characters. If the i-th number is sure to be strictly larger than the actual value, then the i-th character should be '1'. Otherwise, it should be '0'.
对于每组数据,输出一行m个字符,依次回答每个询问。如果一定记多了,请输出'1',否则输出'0'。
Sample Input
3 3
2 5 4
1
7
10000
Sample Output
解题思路:
这道题思路很简单,但是输出的时候晕了,“输出一行,依次回答每个询问,我开始还以为是要将结果存在一起输出,还有换行也没注意,第一遍就WA了5次;
刚才试了一下,将结果存在一个数组,依次输出,最后换行也能AC;
但是最后依然被hack了,前面定义的记录使用的__int64,后面的输入用的却是%d。。。。。彻底无语!
AC代码:
#include<stdio.h>
int main()
{
int t,n,m,i;
int a;
__int64 b[110000];
scanf("%d",&t);
while(t--)
{
__int64 sum=0;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%d",&a);
sum=sum+a;
}
for(i=1;i<=m;i++)
{
scanf("%I64d",&b[i]);
if(b[i]>sum)
printf("1");
else
printf("0");
}
printf("\n");
}
return 0;
}
Problem 1002 NanoApe Loves Sequence
Accept: 0 Submit: 0
Time Limit: 2000/1000 MS (Java/Others) Memory Limit : 262144/131072 K (Java/Others)
Problem Description
NanoApe, the Retired Dog, has returned back to prepare for the National Higher Education Entrance Examination!
In math class, NanoApe picked up sequences once again. He wrote down a sequence with n numbers on the paper and then randomly deleted a number in the sequence. After that, he calculated the maximum absolute value of the difference of each two adjacent remained numbers, denoted as F.
Now he wants to know the expected value of F, if he deleted each number with equal probability.
退役狗 NanoApe 滚回去学文化课啦!
在数学课上,NanoApe 心痒痒又玩起了数列。他在纸上随便写了一个长度为 n 的数列,他又根据心情随便删了一个数,这样他得到了一个新的数列,然后他计算出了所有相邻两数的差的绝对值的最大值。
他当然知道这个最大值会随着他删了的数改变而改变,所以他想知道假如全部数被删除的概率是相等的话,差的绝对值的最大值的期望是多少。
Input
The first line of the input contains an integer T, denoting the number of test cases.
In each test case, the first line of the input contains an integer n, denoting the length of the original sequence.
The second line of the input contains n integers A1,A2,...,An, denoting the elements of the sequence.
1≤T≤10, 3≤n≤100000, 1≤Ai≤10^9
第一行为一个正整数 T,表示数据组数。
每组数据的第一行为一个整数 n。
第二行为 n 个整数 Ai,表示这个数列。
1≤T≤10, 3≤n≤100000, 1≤Ai≤10^9
Output
For each test case, print a line with one integer, denoting the answer.
In order to prevent using float number, you should print the answer multiplied by n.
对于每组数据输出一行一个数表示答案。
为防止精度误差,你需要输出答案乘上 n 后的值。
Sample Input
4
1 2 3 4
Sample Output
解题思路:
这道题刚开始不知道期望是啥意思,百度一下,就是平均值。。。。。。最后要乘n,所以实际上就是求把1-n每个数去掉一编,然后把每次得到的最大相邻两个数的差求和即可;
新序列相对于原来的序列而言,就相当于挖掉了一个数,将该数的左边和右边拼凑成新序列,那我们只需知道左边的最大值与右边的最大值,再和拼接处产生的差值比较一下,就可以知道新序列的最大值即令l[i]表示前i个数两两相邻差值的绝对值的最大值,r[i]表示i到n范围内两两相邻差值的绝对值的最大值。那么枚举删除第i个数,加上删除该数时的序列最大值即可。ans+=max(abs(s[i+1]-s[i-1]),max(l[i-1],r[i+1]))
注意,在删除序列首尾的数时,要特判一下!!!
AC代码:
#include<stdio.h>
#include<math.h>
#include<string.h>
#define G 1100000
int max(int x,int y)
{
if(x>y)
return x;
else
return y;
}
int s[G];
int l[G];
int r[G];
int main()
{
int t,n,i;
__int64 ans;
scanf("%d",&t);
while(t--)
{
ans=0;
memset(l,0,sizeof(l));
memset(r,0,sizeof(r));
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&s[i]);
for(i=1;i<n;i++)
l[i]=max(abs(s[i]-s[i-1]),l[i-1]);
for(i=n-2;i>=0;i--)
r[i]=max(abs(s[i+1]-s[i]),r[i+1]);
for(i=0;i<n;i++)
if(i==0)
ans+=r[i+1];
else if(i==n-1)
ans+=l[i-1];
else
ans+=max(abs(s[i+1]-s[i-1]),max(l[i-1],r[i+1]));
printf("%I64d\n",ans);
}
return 0;
}
Problem 1003 NanoApe Loves Sequence Ⅱ
Accept: 0 Submit: 0
Time Limit: 4000/2000 MS (Java/Others) Memory Limit : 262144/131072 K (Java/Others)
Problem Description
NanoApe, the Retired Dog, has returned back to prepare for for the National Higher Education Entrance Examination!
In math class, NanoApe picked up sequences once again. He wrote down a sequence with n numbers and a number m on the paper.
Now he wants to know the number of continous subsequences of the sequence in such a manner that the k-th largest number in the subsequence is no less than m.
Note : The length of the subsequence must be no less than k.
退役狗 NanoApe 滚回去学文化课啦!
在数学课上,NanoApe 心痒痒又玩起了数列。他在纸上随便写了一个长度为 n 的数列,他又根据心情写下了一个数 m。
他想知道这个数列中有多少个区间里的第 k 大的数不小于 m,当然首先这个区间必须至少要有 k 个数啦。
Input
The first line of the input contains an integer T, denoting the number of test cases.
In each test case, the first line of the input contains three integers n,m,k.
The second line of the input contains n integers A1,A2,...,An, denoting the elements of the sequence.
1≤T≤10, 2≤n≤200000, 1≤k≤n/2, 1≤m,Ai≤10^9
Output
For each test case, print a line with one integer, denoting the answer.
对于每组数据输出一行一个数表示答案。
Sample Input
7 4 2
4 2 7 7 6 5 1
Sample Output
解题思路:
给定一个长度为n的数列,问有多少个区间的第k大数>=m;
第k大,是从大到小排序后第k个(不去重)。
我们只要记录以第i个数作为区间左端点时,右端点延伸到何处能够满足区间内有k个数>=m即可,因为右端点再往右延伸必定满足区间内有k个数>=m;
那么最终结果只需枚举左端点,加上右端点可以取的个数即可
AC代码:
#include<stdio.h>
#define G 1100000
int s[G];
int r[G];
int main()
{
int t,n,m,k,i,j,c;
__int64 ans;
scanf("%d",&t);
while(t--)
{
ans=0;c=0;
scanf("%d%d%d",&n,&m,&k);
for(i=0;i<n;i++)
{
scanf("%d",&s[i]);
r[i]=n;
}
for(j=i=0;i<n;i++)
{
if(s[i]>=m)
c++;
while(c==k)
{
r[j]=i;
if(s[j]>=m)
c--;
j++;
}
}
for(i=0;i<n;i++)
ans+=(n-r[i]);
printf("%I64d\n",ans);
}
return 0;
}
参考地址:http://www.infocool.net/kb/OtherLanguage/201608/173388.html