您的位置:首页 > 大数据 > 人工智能

2016 Multi-University Training Contest 2

2016-07-22 08:09 676 查看

Acperience

[align=center]Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 369    Accepted Submission(s): 189

[/align]

提示:构造一元二次方程,求最小值;

[align=left]Problem Description[/align]
Deep neural networks (DNN) have shown significant improvements in several application domains including computer vision and speech recognition. In computer vision, a particular type of DNN, known as Convolutional Neural Networks (CNN),
have demonstrated state-of-the-art results in object recognition and detection.

Convolutional neural networks show reliable results on object recognition and detection that are useful in real world applications. Concurrent to the recent progress in recognition, interesting advancements have been happening in virtual reality (VR by Oculus),
augmented reality (AR by HoloLens), and smart wearable devices. Putting these two pieces together, we argue that it is the right time to equip smart portable devices with the power of state-of-the-art recognition systems. However, CNN-based recognition systems
need large amounts of memory and computational power. While they perform well on expensive, GPU-based machines, they are often unsuitable for smaller devices like cell phones and embedded electronics.

In order to simplify the networks, Professor Zhang tries to introduce simple, efficient, and accurate approximations to CNNs by binarizing the weights. Professor Zhang needs your help.

More specifically, you are given a weighted vector
W=(w1,w2,...,wn).
Professor Zhang would like to find a binary vector
B=(b1,b2,...,bn)(bi∈{+1,−1})
and a scaling factor α≥0
in such a manner that ∥W−αB∥2
is minimum.

Note that ∥⋅∥
denotes the Euclidean norm (i.e. ∥X∥=x21+⋯+x2n−−−−−−−−−−√,
where X=(x1,x2,...,xn)).
 

[align=left]Input[/align]
There are multiple test cases. The first line of input contains an integerT,
indicating the number of test cases. For each test case:

The first line contains an integers n(1≤n≤100000)
-- the length of the vector. The next line contains
n
integers: w1,w2,...,wn(−10000≤wi≤10000).
 

[align=left]Output[/align]
For each test case, output the minimum value of
∥W−αB∥2
as an irreducible fraction "p/q"
where p,q
are integers, q>0.
 

[align=left]Sample Input[/align]

3
4
1 2 3 4
4
2 2 2 2
5
5 6 2 3 4

 

[align=left]Sample Output[/align]

5/1
0/1
10/1

 

[align=left]Author[/align]
zimpha
 

[align=left]Source[/align]
2016 Multi-University Training Contest 2
 

[align=left]Recommend[/align]
wange2014   |   We have carefully selected several similar problems for you:  5746 5745 5744 5743 5741
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#define LL long long
using namespace std;

int main()
{
LL A,B,C;
int t,n,x;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
A=n;
B=C=0;
while(n--)
{
scanf("%d",&x);
C+=x*x;
if(x>0)
B+=x;
else
B-=x;
}
B*=(-2);
LL Z=(LL)4*A*C-B*B;
LL M=(LL)4*A;
if(Z==0)
printf("0/1\n");
else
{
LL tmp=__gcd(Z,M);
printf("%I64d/%I64d\n",Z/tmp,M/tmp);
}
}
return 0;
}

It's All In The Mind

[align=center]Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 381    Accepted Submission(s): 171

[/align]

分析:简单题;数学分析, 暴力都行(数列个数较小)

Problem Description
Professor Zhang has a number sequence
a1,a2,...,an.
However, the sequence is not complete and some elements are missing. Fortunately, Professor Zhang remembers some properties of the sequence:

1. For every i∈{1,2,...,n},0≤ai≤100.

2. The sequence is non-increasing, i.e. a1≥a2≥...≥an.

3. The sum of all elements in the sequence is not zero.

Professor Zhang wants to know the maximum value of
a1+a2∑ni=1ai
among all the possible sequences.
 

[align=left]Input[/align]
There are multiple test cases. The first line of input contains an integerT,
indicating the number of test cases. For each test case:

The first contains two integers n
and m(2≤n≤100,0≤m≤n)
-- the length of the sequence and the number of known elements.

In the next m
lines, each contains two integers xi
and yi(1≤xi≤n,0≤yi≤100,xi<xi+1,yi≥yi+1),
indicating that axi=yi.
 

[align=left]Output[/align]
For each test case, output the answer as an irreducible fraction "p/q",
where p,q
are integers, q>0.
 

[align=left]Sample Input[/align]

2
2 0
3 1
3 1

 

[align=left]Sample Output[/align]

1/1
200/201

 

[align=left]Author[/align]
zimpha
 

[align=left]Source[/align]
2016 Multi-University Training Contest 2
 

[align=left]Recommend[/align]
wange2014   |   We have carefully selected several similar problems for you:  5746 5745 5744 5743 5741

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
using namespace std;
int A[110];
int main()
{
int n;
int m;
int t;
int x,y;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
memset(A,-1,sizeof(A));
while(m--)
{
scanf("%d%d",&x,&y);
A[x]=y;
}
if(A[1]==-1)
A[1]=100;
if(A[2]==-1)
A[2]=A[1];
if(A
==-1)
A
=0;
for(int i=n-1;i>=3;i--)
{
if(A[i]==-1)
A[i]=A[i+1];
}
int Z=A[1]+A[2];
int M=0;
for(int i=1;i<=n;i++)
M+=A[i];
//         if(Z==0&&M==0)                      //不存在的情况;
//         {
//             printf("1/1\n");
//         }
//         else
{
int d=__gcd(Z,M);
printf("%d/%d\n",Z/d,M/d);
}
}
return 0;
}


 

Keep On Movin

[align=center]Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 226    Accepted Submission(s): 168

[/align]

提示:有多少奇数,至少有多少回文串,奇数=1+偶数,统计总和,尽可能平均分配

Problem Description
Professor Zhang has kinds of characters and the quantity of thei-th
character is ai.
Professor Zhang wants to use all the characters build several palindromic strings. He also wants to maximize the length of the shortest palindromic string.

For example, there are 4 kinds of characters denoted as 'a', 'b', 'c', 'd' and the quantity of each character is{2,3,2,2}
. Professor Zhang can build {"acdbbbdca"}, {"abbba", "cddc"}, {"aca", "bbb", "dcd"}, or {"acdbdca", "bb"}. The first is the optimal solution where the length of the shortest palindromic string is 9.

Note that a string is called palindromic if it can be read the same way in either direction.

 

[align=left]Input[/align]
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integer n(1≤n≤105)
-- the number of kinds of characters. The second line contains
n
integers a1,a2,...,an(0≤ai≤104).
 

[align=left]Output[/align]
For each test case, output an integer denoting the answer.
 

[align=left]Sample Input[/align]

4
4
1 1 2 4
3
2 2 2
5
1 1 1 1 1
5
1 1 2 2 3

 

[align=left]Sample Output[/align]

3
6
1
3

 

[align=left]Author[/align]
zimpha
 

[align=left]Source[/align]
2016 Multi-University Training Contest 2
 

[align=left]Recommend[/align]
wange2014   |   We have carefully selected several similar problems for you:  5746 5745 5744 5743 5741

 

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
const int N=1e5+10;
int A
;
int main()
{
int t,n,k,x;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
k=0;
int sum=0;
for(int i=0;i<n;i++)
{
scanf("%d",&x);
if(x%2)
A[k++]=x;
sum+=x;
}
if(k==0)
printf("%d\n",sum);
else
{
sum-=k;
printf("%d\n",1+sum/(2*k)*2);
}
}
return 0;
}


La Vie en rose

[align=center]Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 371    Accepted Submission(s): 172

[/align]

提示:不必纠结用p串的每一种变形都去匹配s串,只需判断s串从某位置起是否是p串的变形;

Problem Description
Professor Zhang would like to solve the multiple pattern matching problem, but he only has only one pattern stringp=p1p2...pm.
So, he wants to generate as many as possible pattern strings from
p
using the following method:

1. select some indices i1,i2,...,ik
such that 1≤i1<i2<...<ik<|p|
and |ij−ij+1|>1
for all 1≤j<k.

2. swap pij
and pij+1
for all 1≤j≤k.

Now, for a given a string s=s1s2...sn,
Professor Zhang wants to find all occurrences of all the generated patterns in
s.
 

[align=left]Input[/align]
There are multiple test cases. The first line of input contains an integerT,
indicating the number of test cases. For each test case:

The first line contains two integers n
and m(1≤n≤105,1≤m≤min{5000,n})
-- the length of s
and p.

The second line contains the string s
and the third line contains the string p.
Both the strings consist of only lowercase English letters.
 

[align=left]Output[/align]
For each test case, output a binary string of length
n.
The i-th
character is "1" if and only if the substring sisi+1...si+m−1
is one of the generated patterns.
 

[align=left]Sample Input[/align]

3
4 1
abac
a
4 2
aaaa
aa
9 3
abcbacacb
abc

 

[align=left]Sample Output[/align]

1010
1110
100100100

 

[align=left]Author[/align]
zimpha
 

[align=left]Source[/align]
2016 Multi-University Training Contest 2
 

[align=left]Recommend[/align]
wange2014   |   We have carefully selected several similar problems for you:  5746 5745 5743 5741 5740 
 

 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define LL long long
using namespace std;
const int N=1e6+10;
char s
;
char p[5010];
int main()
{
int t,n,m;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
scanf("%s%s",s,p);
for(int i=0;i<n;i++)
{
int l=i;
int flag=1;
if(i>n-m)
{
printf("0");
continue;
}
for(int j=0;j<m;j++,l++)
{
if(s[l]!=p[j])
{
if(j<m-1&&s[l]==p[j+1]&&s[l+1]==p[j])
j++,l++;
else
{
flag=0;
break;
}
}

}  printf("%d",flag);
}
printf("\n");
}
return 0;
}

Eureka

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

Total Submission(s): 2143    Accepted Submission(s): 643

所要求的:同意直线上所有子集的个数;

关键 :去重,保证不重复记录

[align=left]Problem Description[/align]
Professor Zhang draws n
points on the plane, which are conveniently labeled by
1,2,...,n.
The i-th
point is at (xi,yi).
Professor Zhang wants to know the number of best sets. As the value could be very large, print it modulo
109+7.

A set P
(P
contains the label of the points) is called best set if and only if there are at least one best pair in
P.
Two numbers u
and v
(u,v∈P,u≠v)
are called best pair, if for every w∈P,
f(u,v)≥g(u,v,w),
where f(u,v)=(xu−xv)2+(yu−yv)2−−−−−−−−−−−−−−−−−−√
and g(u,v,w)=f(u,v)+f(v,w)+f(w,u)2.
 

[align=left]Input[/align]
There are multiple test cases. The first line of input contains an integer
T,
indicating the number of test cases. For each test case:

The first line contains an integer n
(1≤n≤1000)
-- then number of points.

Each of the following n
lines contains two integers xi
and yi
(−109≤xi,yi≤109)
-- coordinates of the i-th
point.
 

[align=left]Output[/align]
For each test case, output an integer denoting the answer.
 

[align=left]Sample Input[/align]

3
3
1 1
1 1
1 1
3
0 0
0 1
1 0
1
0 0

 

[align=left]Sample Output[/align]

4
3
0

 

[align=left]Author[/align]
zimpha
 

[align=left]Source[/align]
2016 Multi-University Training Contest 2

 

[align=left]Recommend[/align]
wange2014   |   We have carefully selected several similar problems for you:  5751 5750 5749 5748 5747 
 

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define LL long long
using namespace std;
const LL MOD=1e9+7;
LL A[1010];
struct node
{
int x,y;
bool operator <(const node &A)const
{
return (x==A.x)?y<A.y:x<A.x;
}
bool operator ==(const node &A)const
{
if(x==A.x&&y==A.y)
return 1;
return 0;
}

}que[1010];
map<node,LL>M;
map<node,LL>::iterator it;
int main()
{
int t,n;
A[0]=1;
for(int i=1;i<=1001;i++)
{
(A[i]=A[i-1]*2)%=MOD;
}
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d",&que[i].x,&que[i].y);
}
LL ans=0;
int d;
int xx,yy;
for(int i=0;i<n;i++)
{
M.clear();
int cnt=1;
for(int j=i+1;j<n;j++)
{
if(que[i]==que[j])
{
cnt++;
continue;
}
xx=que[i].x-que[j].x,yy=que[i].y-que[j].y;
d=__gcd(xx,yy);
xx/=d,yy/=d;
M[node{xx,yy}]++;
}
if(cnt>1)
{
(ans+=(A[cnt-1]-1))%=MOD;
}
for(it=M.begin();it!=M.end();it++)
{

(ans+=(A[cnt-1])*(A[it->second]-1))%=MOD;
}
}
printf("%lld\n",(ans%MOD+MOD)%MOD);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: