杭电多校第一场-M-Code
题目描述
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 x∈Rd, and outputs y∈{−1,1}. We will try to find a function

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=b, x0=1, then

To solve the problem, we have a algorithm, PLA(Popcorn Label Algorithm).
Accoding to PLA, we will randomly generate w.
If f(x)=sign(wT⋅x) 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.

输入
Each test case begins with a line containing a single integer n(1≤n≤100), size of the set of training samples D.
Then n lines follow, the ith of which contains three integers xi,1,xi,2,yi (−105≤xi,1,xi,2≤105, yi∈{−1,1}), indicating the ith sample (xi,yi) in D, where xi=(xi,1,xi,2).
输出
题意是给你n个三元组(x1,x2,y),问你是否存在a,b,c使得对所有的三元组满足sgn(ax1+bx2+c)=y; 官方题解:
d= 时,f(x) =sgn(ax1+bx2+c),f(x) = 对应于二维平面上的一条直线,直线一侧的点取值为 ,直线另一侧的取值为 -。
故该问题等价于能否找到一条直线将平面上的两类点分开,等价于判断这两类点分别组成的两个凸包是否相交。
判断凸包是否相交,参考https://www.cnblogs.com/ITUPC/p/5987593.html
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const double eps=1e-;
const int N=;
int sgn(double x)
{
if (fabs(x)<eps)return ;
if (x<)return -;
else return ;
}
struct Point {
ll x,y;
Point() {}
Point(ll _x,ll _y)
{
x=_x; y=_y;
}
Point operator -(const Point &b)
{
return Point(x-b.x,y-b.y);
}
ll operator ^(const Point &b)
{
return x*b.y-y*b.x;
}
ll operator *(const Point &b)
{
return x*b.x+y*b.y;
}
bool operator<(const Point &b)const
{
if(fabs(y-b.y)<eps) return x<b.x;
return y<b.y;
}
};
double Length(Point A)
{
return sqrt(A*A);
}
double Angle(Point A,Point B)
{
return acos((A*B)/Length(A)/Length(B));
}
bool Inter(Point a1,Point a2,Point b1,Point b2)
{
ll c1=(a2-a1)^(b1-a1),c2=(a2-a1)^(b2-a1),c3=(b2-b1)^(a1-b1),c4=(b2-b1)^(a2-b1);
return sgn(c1)*sgn(c2)<&&sgn(c3)*sgn(c4)<;
} int Graham(Point p[],int n,Point q[])
{
int top=;
sort(p,p+n);
if (n==) return ;
q[]=p[];
if (n==) return ;
q[]=p[];
if (n==) return ;
q[]=p[];
for (int i=;i<n;i++)
{
while(top&&((q[top]-q[top-])^(p[i]-q[top-]))<=) top--;
q[++top]=p[i];
}
int len=top;
q[++top]=p[n-];
for (int i=n-;i>=;i--)
{
while (top!=len&&((q[top]-q[top-])^(p[i]-q[top-]))<=) top--;
q[++top]=p[i];
}
return top;
} bool C_S(Point ch1[],int t1,Point ch2[],int t2)
{
if (t1==) return ;
double angle[],x;
int i,j,k;
if (t1==)
{
for(i=;i<t2;i++)
{
k=sgn((ch1[]-ch1[])^(ch2[i]-ch1[]));
if (k== && (ch1[]-ch1[])*(ch2[i]-ch1[])>)
{
if (Length(ch2[i]-ch1[])<Length(ch1[]-ch1[])) break;
}
}
if (i<t2) return ;
if (t2== && Inter(ch1[],ch1[],ch2[],ch2[])) return ;
return ;
}
angle[]=;
for (int i=;i<t1;i++) angle[i-]=Angle(ch1[]-ch1[],ch1[i]-ch1[]);
for (i=;i<t2;i++)
{
j=sgn((ch1[]-ch1[])^(ch2[i]-ch1[]));
if (j< || (j== && (ch1[]-ch1[])*(ch2[i]-ch1[])<)) continue;
j=sgn((ch1[t1-]-ch1[])^(ch2[i]-ch1[]));
if (j> || (j== && (ch1[t1-]-ch1[])*(ch2[i]-ch1[])<)) continue;
x=Angle(ch1[]-ch1[],ch2[i]-ch1[]);
int m=lower_bound(angle,angle+t1-,x)-angle;
if (m==) j=; else j=m-;
k=sgn((ch1[j+]-ch2[i])^(ch1[j+]-ch2[i]));
if (k>=) break;
}
if (i<t2) return ;
return ;
}
Point p1[N],p2[N],ch1[N],ch2[N];
int T,n;
int main()
{
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int cnt1=,cnt2=;
ll x,y; int z;
for(int i=;i<n;i++)
{
scanf("%lld%lld%d",&x,&y,&z);
if (z==) p1[cnt1++]=Point(x,y);
else p2[cnt2++]=Point(x,y);
}
int t1=Graham(p1,cnt1,ch1);
int t2=Graham(p2,cnt2,ch2);
if (C_S(ch1,t1,ch2,t2)&&C_S(ch2,t2,ch1,t1)) printf("Successful!\n");
else printf("Infinite loop!\n");
}
//fclose(stdin);
//fclose(stdout);
return ;
}
杭电多校第一场-M-Code的更多相关文章
- 2018 Multi-University Training Contest 1 杭电多校第一场
抱着可能杭电的多校1比牛客的多校1更恐怖的想法 看到三道签到题 幸福的都快哭出来了好吗 1001 Maximum Multiple(hdoj 6298) 链接:http://acm.hdu.edu. ...
- 2019杭电多校第一场hdu6581 Vacation
Vacation 题目传送门 update(O(n)) 看了那个O(n)的方法,感觉自己想的那个O(nlogn)的好傻,awsl. 0车最终通过停车线的时候,状态一定是某个车堵住后面的所有车(这个车也 ...
- 2019年杭电多校第一场 1009题String(HDU6586+模拟+单调栈)
题目链接 传送门 题意 给你一个字符串,要你构造一个长为\(k\)的子串使得每个字母出现的次数在\([L_i,R_i](0\leq i\leq26)\)间且字典序最小. 思路 做这种题目就是要保持思路 ...
- 2019年杭电多校第一场 1004题Vacation(HDU6581+数学)
题目链接 传送门 题意 有\(n+1\)辆车要过红绿灯,告诉你车的长度.与红绿灯的起点(题目假设红绿灯始终为绿).车的最大速度,问你第\(0\)辆车(距离最远)车头到达红绿灯起点的时间是多少(每辆车最 ...
- 2019年杭电多校第一场 1002题Operation(HDU6579+线性基)
题目链接 传送门 题意 初始时有\(n\)个数,现在有\(q\)次操作: 查询\([l,r]\)内选择一些数使得异或和最大: 在末尾加入一个数. 题目强制在线. 思路 对于\(i\)我们记录\([1, ...
- [2019杭电多校第一场][hdu6582]Path(最短路&&最小割)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6582 题意:删掉边使得1到n的最短路改变,删掉边的代价为该边的边权.求最小代价. 比赛时一片浆糊,赛后 ...
- [2019杭电多校第一场][hdu6583]Typewriter(后缀自动机&&dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6583 大致题意是说可以花费p在字符串后添加一个任意字符,或者花费q在字符串后添加一个当前字符串的子串. ...
- [2019杭电多校第一场][hdu6579]Operation(线性基)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6579 题目大意是两个操作,1个是求[l,r]区间子序列的最大异或和,另一个是在最后面添加一个数. 如果 ...
- [2019杭电多校第一场][hdu6578]Blank(dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6578 计数问题想到dp不过分吧... dp[i][j][k][w]为第1-i位置中4个数最后一次出现的 ...
- 2019杭电多校第一场hdu6579 Operation(线性基)
Operation 题目传送门 解题思路 把右边的数尽量往高位放,构造线性基的时候同时记录其在原序列中的位置,在可以插入的时候如果那个位置上存在的数字的位置比新放入的要小,就把旧的往后挤.用这种发现构 ...
随机推荐
- c# 排序算法可视化
最近在 b 站上看了一个排序算法的动画,所以想自己写一个类似的项目. 项目使用 Graphics 在 winform 的窗体上绘图.(新建项目时选择控制台项目,注意添加引用:System.Drawin ...
- Permission denied
记录在一次启动tomcat时提示:Permission denied 信息. 解释一下Permission denied的意思-没有权限 解决办法: sudo chmod -R 777 某一目录其中- ...
- JSONObject.toJSONString(map)
Map<Integer, List<Integer>> map = new LinkedHashMap<>(); map.put(1,ddzCard.getOneS ...
- 使用truelicense实现用于JAVA工程license机制(包括license生成和验证)
开发的软件产品在交付使用的时候,往往会授权一段时间的试用期,这个时候license就派上用场了.不同于在代码中直接加上时间约束,需要重新授权的时候使用license可以避免修改源码,改动部署,授权方直 ...
- #ifdef 宏定义一个main编译客户端服务端2套代码
#include <iostream> using namespace std; #include "ProWrapper.h" #include "Serv ...
- linux中的read_link
readlink是linux系统中一个常用工具,主要用来找出符号链接所指向的位置. readlink 获取当前进程对应proc/self/exe]:shell中 readlink /proc/sel ...
- hdu 5791 思维dp
题目描述: 求序列A,B的公共子序列个数: 基本思路: 想到了dp,选的状态也对,但是就是就是写不出状态转移方程,然后他们都出了,到最后我还是没出,很难受,然后主要是没有仔细考虑dp[i][j],dp ...
- 6383. 【NOIP2019模拟2019.10.07】果实摘取
题目 题目大意 给你一个由整点组成的矩形,坐标绝对值范围小于等于\(n\),你在\((0,0)\),一开始面向\((1,0)\),每次转到后面第\(k\)个你能看到的点,然后将这条线上的点全部标记删除 ...
- JPA中遇到一些异常的分析与解决
Spring Data JPA踩坑到填坑:1 JPA多对多关 //作者表 //书籍表 Book和Author是多对多关系 先放两张图做个说明:Jpa底层依赖于hibernate,hibernate默认 ...
- homebrew -- mac os 系统下的 apt-get、yum
linux下有很方便的包管理器如:apt-get.yum,mac下也有类似的工具:Homebrew 和 Fink.MacPort.Flink是直接编译好的二进制包,MacPorts是下载所有依赖库的源 ...