您的位置:首页 > 理论基础 > 计算机网络

2016中国大学生程序设计竞赛 - 网络选拔赛

2016-08-14 23:51 429 查看
TAT   TAT   TAT

到了写题解的时刻了,真的很想吐槽这回的题,真心坑啊,明明一道题原理很简单,可是出题人非要把题目叙述的那么繁琐,让人走进思想死胡同,越想越复杂,可能题目就是要坑人吧==!不说了开始写题解。这回坑就坑在1004题了,明明描述的是单调递增最长上升子序列,死活代码敲出,用dp过了一遍,之后便提交之后居然超时TLE了,内心奔溃到极点,攻了一个小时这道水题,又把时间复杂度优化到nlogn,真没想到立刻WA了TAT。过了很长时间,之后试了一下是不是计算不同字符的个数,没想到一写,A了,只想说出题人你......不喷了,上代码!!!


A water problem

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 296    Accepted Submission(s): 166


Problem Description

Two planets named Haha and Xixi in the universe and they were created with the universe beginning.

There is 73 days
in Xixi a year and 137 days
in Haha a year. 

Now you know the days N after
Big Bang, you need to answer whether it is the first day in a year about the two planets.

 

Input

There are several test cases(about 5 huge
test cases).

For each test, we have a line with an only integer N(0≤N),
the length of N is
up to 10000000.

 

Output

For the i-th test case, output Case #i: , then output "YES" or "NO" for the answer.

 

Sample Input

10001
0
333

 

Sample Output

Case #1: YES
Case #2: YES
Case #3: NO

 
1001这道题是道水题,读完题发现数可以整除73和137即可,不过数据之大,要用大数写,用字符数组存,之后便AC了。

#include<stdio.h>
#include<string.h>
#define mod1 73
#define mod2 137
char s[10000005];
int main()
{
int l,i,t=1;
long long a,b;
while(~scanf("%s",s))
{
a=0,b=0;
l=strlen(s);
for(i=0;i<l;i++)
{
a=(a*10+s[i]-'0')%mod1;
b=(b*10+s[i]-'0')%mod2;
}
if(a==0&&b==0)
printf("Case #%d: YES\n",t);
else
printf("Case #%d: NO\n",t);
t++;
}
return 0;
}



Lweb and String

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 212    Accepted Submission(s): 136


Problem Description

Lweb has a string S.

Oneday, he decided to transform this string to a new sequence. 

You need help him determine this transformation to get a sequence which has the longest LIS(Strictly Increasing). 

You need transform every letter in this string to a new number.

A is
the set of letters of S, B is
the set of natural numbers. 

Every injection f:A→B can
be treat as an legal transformation. 

For example, a String “aabc”, A={a,b,c},
and you can transform it to “1 1 2 3”, and the LIS of the new sequence is 3. 

Now help Lweb, find the longest LIS which you can obtain from S.

LIS: Longest Increasing Subsequence. (https://en.wikipedia.org/wiki/Longest_increasing_subsequence)

 

Input

The first line of the input contains the only integer T,(1≤T≤20).

Then T lines
follow, the i-th line contains a string S only
containing the lowercase letters, the length of S will
not exceed 105.

 

Output

For each test case, output a single line "Case #x: y", where x is the case number, starting from 1. And y is the answer.

 

Sample Input

2
aabcc
acdeaa

 

Sample Output

Case #1: 3
Case #2: 4

 

这就是那道让我很无语的题,不是单调最长上升子序列,只想说题目明明就是那么叙述的啊啊啊!!!其实他只是计算不同的字母个数。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int t,num=1;
char a[100005];
int len,i;
scanf("%d",&t);
while(t--)
{
int count=1;
scanf("%s",a);
len=strlen(a);
sort(a,a+len);
for(i=0;i<len-1;i++)
{
if(a[i]!=a[i+1])
count++;
}
printf("Case #%d: %d\n",num++,count);
}
return 0;
}



Zhu and 772002

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 381    Accepted Submission(s): 118


Problem Description

Zhu and 772002 are both good at math. One day, Zhu wants to test the ability of 772002, so he asks 772002 to solve a math problem. 

But 772002 has a appointment with his girl friend. So 772002 gives this problem to you.

There are n numbers a1,a2,...,an.
The value of the prime factors of each number does not exceed 2000,
you can choose at least one number and multiply them, then you can get a number b.

How many different ways of choices can make b is
a perfect square number. The answer maybe too large, so you should output the answer modulo by 1000000007.

 

Input

First line is a positive integer T ,
represents there are T test
cases.

For each test case:

First line includes a number n(1≤n≤300),next
line there are n numbers a1,a2,...,an,(1≤ai≤1018).

 

Output

For the i-th test case , first output Case #i: in a single line.

Then output the answer of i-th test case modulo by 1000000007.

 

Sample Input

2
3
3 3 4
3
2 2 2

 

Sample Output

Case #1:
3Case #2:
3


Danganronpa

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 276    Accepted Submission(s): 192


Problem Description

Chisa Yukizome works as a teacher in the school. She prepares many gifts, which consist of n kinds
with a[i] quantities
of each kind, for her students and wants to hold a class meeting. Because of the busy work, she gives her gifts to the monitor, Chiaki Nanami. Due to the strange design of the school, the students' desks are in a row. Chiaki Nanami wants to arrange gifts like
this:

1. Each table will be prepared for a mysterious gift and an ordinary gift.

2. In order to reflect the Chisa Yukizome's generosity, the kinds of the ordinary gift on the adjacent table must be different.

3. There are no limits for the mysterious gift.

4. The gift must be placed continuously.

She wants to know how many students can get gifts in accordance with her idea at most (Suppose the number of students are infinite). As the most important people of her, you are easy to solve it, aren't you?

 

Input

The first line of input contains an integer T(T≤10) indicating
the number of test cases.

Each case contains one integer n.
The next line contains n (1≤n≤10) numbers: a1,a2,...,an, (1≤ai≤100000).

 

Output

For each test case, output one line containing “Case #x: y” (without quotes) , where x is the test case number (starting from 1) and y is the answer of Chiaki Nanami's question.

 

Sample Input

1
2
3 2

 

Sample Output

Case #1: 2

TAT这道题,被题的意思绕啊绕,什么神秘礼物,普通礼物,绕来绕去,题意是n种礼物,a[i]....a
表示第i中的礼物的个数,相邻同学的礼物不能相同,问有多少人个同学能拿到符合要求的礼物。

其实就是只需要一人两礼物能分多少人的问题

#include<bits/stdc++.h>
using namespace std;
#define N 12000
#define INF 0x3f3f3f3f
int a
;
int main()
{
int T,n,i,sum,k=1;
scanf("%d", &T);
while(T--)
{
sum=0;
scanf("%d", &n);
for(i=0;i<n;i++)
{
scanf("%d", &a[i]);
sum+=a[i];
}
printf("Case #%d: ",k++);
if(sum==1)
printf("1\n");
else
printf("%d\n", sum/2);
}
return 0;
}



Special Tetrahedron

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 440    Accepted Submission(s): 188


Problem Description

Given n points
which are in three-dimensional space(without repetition).

Please find out how many distinct Special Tetrahedron among them. A tetrahedron is called Special Tetrahedron if it has two following characters.

1. At least four edges have the same length.

2. If it has exactly four edges of the same length, the other two edges are not adjacent.

 

Input

Intput contains multiple test cases. 

The first line is an integer T,1≤T≤20,
the number of test cases.

Each case begins with an integer n(n≤200),
indicating the number of the points.

The next n lines
contains three integers xi,yi,zi, (−2000≤xi,yi,zi≤2000),
representing the coordinates of the ith point.

 

Output

For each test case,output a line which contains"Case #x: y",x represents the xth test(starting from one),y is the number of Special Tetrahedron.

 

Sample Input

2
4
0 0 0
0 1 1
1 0 1
1 1 0
9
0 0 0
0 0 2
1 1 1
-1 -1 1
1 -1 1
-1 1 1
1 1 0
1 0 1
0 1 1

 

Sample Output

Case #1: 1
Case #2: 6

解题思路:

【题意】

在三维空间中给出n个点,问你有多少个特殊四面体

特殊四面体定义如下:

1.至少四条边相等;

2.如果恰好只有四条边相等,那么不相等的两条边不相邻

如图



当AB=AC=BD=CD≠(AD,BC),此时,AD与BC异面(不相邻),满足特殊四面体定义第2条

【类型】

计算几何

【分析】

n^4暴力,但实际上复杂度达不到n^4【虽然我觉得还是可以卡掉的,可能是出题人懒得出这种数据了】

暴力枚举两个点,然后再枚举离这两点距离相同的点,如下图



再枚举四个点,判断其构成的四面体是否四条边相等(即

),但是不共面(比如点A,B,C,D,共面可以通过3点(A,B,C)所构成的平面的平面法向量与其中一个向量(A->D)是否垂直来判断)



再判断这个是不是正四面体,如果是正四边形的话,暴力枚举过程会使得该四面体被重复计算6次(四面体4个顶点任取两个,C(4,2)=6)

否则该四面体被重复计算两次(A与D,B与C两种取法)

【时间复杂度&&优化】

O(n^4)

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#define eps 1e-9
#define LL long long
using namespace std;
const int N = 205;
const int M = 2001;
const int inf = 1000000007;
const int mod = 1000000007;
struct node
{
int x,y,z;
}s
;
int ans
;
node xmult(node u,node v)//计算 cross product U x V
{
node ret;
ret.x=u.y*v.z-v.y*u.z;
ret.y=u.z*v.x-u.x*v.z;
ret.z=u.x*v.y-u.y*v.x;
return ret;
}
int dmult(node u,node v)//计算 dot product U . V
{
return u.x*v.x+u.y*v.y+u.z*v.z;
}
node subt(node u,node v)//矢量差 U - V
{
node ret;
ret.x=u.x-v.x;
ret.y=u.y-v.y;
ret.z=u.z-v.z;
return ret;
}
node pvec(node s1,node s2,node s3)//取平面法向量
{
return xmult(subt(s1,s2),subt(s2,s3));
}
bool dots_onplane(node a,node b,node c,node d)//判四点共面
{
return !dmult(pvec(a,b,c),subt(d,a));
}
int distant(node p1,node p2)
{
return (p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)+(p2.z-p1.z)*(p2.z-p1.z);
}
int main()
{
int t,n,i,j,k,l,p=1,c,ans1,ans2;
scanf("%d",&t);
while(t--)
{
ans1=ans2=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d%d%d",&s[i].x,&s[i].y,&s[i].z);
for(i=0;i<n;i++)//第1个点
for(j=i+1;j<n;j++)//第2个点
{
c=0;
for(k=0;k<n;k++)//第3个点
{
if(k==j||k==i)
continue;
if(distant(s[k],s[i])==distant(s[k],s[j]))//第3个点到第1个点和第2个点的距离相等
ans[c++]=k;
}
if(c<=1)//构不成4个点
continue;
for(k=0;k<c;k++)
for(l=k+1;l<c;l++)
{
if(distant(s[ans[k]],s[i])!=distant(s[ans[l]],s[i]))//四条边不相等
continue;
if(dots_onplane(s[ans[k]],s[i],s[ans[l]],s[j]))//四点共面
continue;
if(distant(s[ans[k]],s[ans[l]])==distant(s[i],s[j])&&distant(s[i],s[j])==distant(s[ans[k]],s[i]))//六条边相等
ans2++;
else
ans1++;
}
}
printf("Case #%d: %d\n",p++,ans1/2+ans2/6);
}
return 0;
}


其他题还在补,补完就上题解。。。待续~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: