Problem 2972 --Code

2972: Code

"
Time Limit $1$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $3$ 正确数量 $2$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
After returning with honour from ICPC(International Cat Programming Contest) World Finals, Tom decides to say goodbye to ICPC and start a new period of life. He quickly gets interested in AI. 

In the subject of Machine Learning, there is a classical classification model called perceptron, defined as follows: 


Assuming we get a set of training samples: D={(x1,y1),(x2,y2),...,(xN,yN)}, with their inputs xRd, and outputs y{1,1}. We will try to find a function 
f(x)=sign(di=1wixi+b)=sign(wTx+b) so that f(xi)=yi,i=1,2,...,N

w,x mentioned above are all d-dimensional vectors, i.e. w=(w1,w2,...,wd)x=(x1,x2,...,xd). To simplify the question, let w0=bx0=1, then f(x)=sign(di=0wixi)=sign(wTx). Therefore, finding a satisfying function f(x) is equivalent to finding a proper w

To solve the problem, we have a algorithm, PLA(Popcorn Label Algorithm)

Accoding to PLA, we will randomly generate w

If f(x)=sign(wTx) fails to give 
any element (xi,yi)D the right classification, i.e. f(xi)yi, then we will replace w with another random vector. We will do this repeatedly until all the samples D are correctly classified. 

As a former-JBer, Tom excels in programming and quickly wrote the pseudocode of PLA

w := a random vector
while true do
    flag:=true
    for i:=1 to N do
        if f(x[ i ]) != y[ i ] then
            flag:=false
            break
    if flag then
        break
    else
        w := a random vector
return w


But Tom found that, in some occasions, PLA will end up into an infinite loop, which confuses him a lot. You are required to help Tom determine, when performed on a given sample set D, if PLA will end up into an infinite loop. Print Infinite loop! if so, or Successful! otherwise. 

We only consider cases when d=2 for simplification. 
Note: 
The first line contains an integer T(1≤T≤1000)T(1≤T≤1000), the number of test cases. 
Each test case begins with a line containing a single integer n(1≤n≤100)n(1≤n≤100), size of the set of training samples DD
Then nn lines follow, the iith of which contains three integers xi,1,xi,2,yixi,1,xi,2,yi (−105≤xi,1,xi,2≤105,(−105≤xi,1,xi,2≤105, yi∈{−1,1})yi∈{−1,1}), indicating the iith sample (xi,yi)(xi,yi) in DD, where xi=(xi,1,xi,2)xi=(xi,1,xi,2).
For each test case, output a single line containing the answer: “Infinite loop!” or “Successful!”.
3
2
1 1 1
2 0 -1
4
0 0 1
2 0 -1
1 1 1
1 -1 -1
6
0 0 1
2 0 -1
1 1 1
1 -1 -1
1 0 1
0 1 -1
Successful!
Successful!
Infinite loop!

推荐代码 查看2972 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$153 $ms] 淡意的温柔 605347 2020-07-03 15:09:30
内存最少[$1956 $KB] 淡意的温柔 605347 2020-07-03 15:09:30
第一AC 刘成健 462828 2019-09-07 17:31:46
第一挑战 刘成健 462828 2019-09-07 17:31:46

赛题来源/所属竞赛 2019 Multi-University Training Contest 1 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛