本文整理汇总了C++中poly类的典型用法代码示例。如果您正苦于以下问题:C++ poly类的具体用法?C++ poly怎么用?C++ poly使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了poly类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: cut
void cut(poly &p){
bool flag = 1;
while(flag && p.s() > eps){
flag = 0;
rep(i, n)
if(cross(l[i], p)){
poly *L = new poly();
int st = 0, sz = p.ver.size();
for(; !cross(line(p.ver[st], p.ver[(st + 1) % sz]), l[i]); st = (st + 1) % sz);
L->ver.pb(crossPoint(line(p.ver[st], p.ver[(st + 1) % sz]), l[i]));
for(st = (st + 1) % sz; !cross(line(p.ver[st], p.ver[(st + 1) % sz]), l[i]); st = (st + 1) % sz)
L->ver.pb(p.ver[st]);
L->ver.pb(p.ver[st]);
L->ver.pb(crossPoint(line(p.ver[st], p.ver[(st + 1) % sz]), l[i]));
cut(*L);
L->ver.clear();
L->ver.pb(crossPoint(line(p.ver[st], p.ver[(st + 1) % sz]), l[i]));
for(st = (st + 1) % sz; !cross(line(p.ver[st], p.ver[(st + 1) % sz]), l[i]); st = (st + 1) % sz)
L->ver.pb(p.ver[st]);
L->ver.pb(p.ver[st]);
L->ver.pb(crossPoint(line(p.ver[st], p.ver[(st + 1) % sz]), l[i]));
p.ver = L->ver;
delete(L);
flag = 1;
}
}
double s = p.s();
if(s > eps && s < inf)
ans.pb(s);
}
开发者ID:quietshu,项目名称:Algorithm-Contests-Codes,代码行数:32,代码来源:A.cpp
示例2: mult
poly mult(poly& p1,poly& p2){
poly ret(p1.size()+p2.size()-1,0);
for(int i=0;i<p1.size();i++){
for(int j=0;j<p2.size();j++){
ret[i+j]+=p1[i]*p2[j];
}
}
return ret;
}
开发者ID:vipulharsh,项目名称:Coding,代码行数:9,代码来源:wto.cpp
示例3: bisect
double bisect(const poly &p, double lower, double upper) {
if (upper - lower < 1e-5) return lower;
double mid = (lower + upper) / 2;
if (sgn(p.eval(mid)) == sgn(p.eval(lower))) {
return bisect(p, mid, upper);
} else {
return bisect(p, lower, mid);
}
}
开发者ID:MO2013,项目名称:practice,代码行数:9,代码来源:rootfind.cpp
示例4: is_inside
// Test whether point a is inside poly p
bool is_inside(const point & a, const poly & p) {
unsigned i;
int n = p.size();
bool tmp, b = false;
for (i = 0; i < p.size(); i++) {
tmp = intersect(a, e, p[i], p[(i + 1) % n]);
b = (b != tmp);
}
return b;
}
开发者ID:jdumas,项目名称:acm,代码行数:11,代码来源:Submarines_3023.cpp
示例5: ret
poly operator*(const poly &a, const poly &b)
{
poly ret(max(0, (int)a.size() + (int)b.size() - 1), 0.0);
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < b.size(); j++) {
ret[i + j] += a[i] * b[j];
}
}
return ret;
}
开发者ID:EC-Ecstasy,项目名称:mithril,代码行数:10,代码来源:D.cpp
示例6: memset
void MeshData::GenerateNormals(
const bool& InvertNormals)
{
// Sources
const AttribData<vec3> & Vertices = m_VertexArray;
const AttribData<poly> & Faces = m_Polygons;
vec3* pNormals = new vec3[Vertices.Size()];
memset(pNormals, 0, Vertices.Size() * sizeof(vec3));
// Go through the polylists
const uint NrPolyLists = Faces.Size();
for(uint p=0; p<NrPolyLists; p++) {
const poly Polylist = Faces.GetElem(p);
const uint NrFaces = Polylist.NrFaces();
for(uint f=0; f<NrFaces; f++)
{
// Get vertices
const uint i1 = Polylist.GetFaces().GetElem(f).v1;
const uint i2 = Polylist.GetFaces().GetElem(f).v2;
const uint i3 = Polylist.GetFaces().GetElem(f).v3;
const vec3 v1 = Vertices.GetElem(i1);
const vec3 v2 = Vertices.GetElem(i2);
const vec3 v3 = Vertices.GetElem(i3);
// Get edges
const vec3 edge1 = v2-v1; const vec3 edge2 = v3-v1;
// Set Crossproduct
vec3 facenormal;
if(InvertNormals) {
facenormal=normalize(glm::cross(edge1, edge2));
facenormal = facenormal * -1.0f;
} else
facenormal=normalize(glm::cross(edge1, edge2));
// Add vertexnormals
pNormals[i1]+=facenormal;
pNormals[i2]+=facenormal;
pNormals[i3]+=facenormal;
}
}
// Normalize
vec3* pN = pNormals;
for(uint n=0; n<Vertices.Size(); n++, pN++)
*pN = normalize(*pN);
MeshData::SetNormalArray().Load(pNormals, Vertices.Size());
delete [] pNormals;
}
开发者ID:TimelessVisions,项目名称:GLEngine,代码行数:54,代码来源:GLData.cpp
示例7:
poly operator+(const poly &a, const poly &b)
{
poly ret = a;
if (ret.size() < b.size()) {
ret.resize(b.size(), 0.0);
}
for (int i = 0; i < b.size(); i++) {
ret[i] += b[i];
}
return ret;
}
开发者ID:EC-Ecstasy,项目名称:mithril,代码行数:11,代码来源:D.cpp
示例8: normalize
void normalize(poly &p)
{
int minx=1000 , miny=1000 ;
for(int i=0;i<p.size();i++)
{
minx=min(minx,p[i].x) ;
miny=min(miny,p[i].y) ;
}
poly q ;
for(int i=0;i<p.size();i++)
q.push_back((P){p[i].x-minx,p[i].y-miny}) ;
p=q ;
}
开发者ID:a00012025,项目名称:Online_Judge_Code,代码行数:13,代码来源:b382(2).cpp
示例9: read
void read( poly& pp , string ss , LL mod ){
pp.clear();
if( ss[ 0 ] != '-' ) ss = '+' + ss;
size_t st = 0;
while( st < ss.length() ){
size_t lst = st;
st ++;
while( st < ss.length() and
ss[ st ] != '+' and
ss[ st ] != '-' ) st ++;
pp.push_back( parse( ss , lst , st , mod ) );
}
}
开发者ID:tzupengwang,项目名称:PECaveros,代码行数:13,代码来源:b.cpp
示例10: add
poly add(poly p1,poly p2){
if(p1.size()>=p2.size()){
for(int i=0;i<p2.size();i++){
p1[i]+=p2[i];
}
return p1;
}
else{
for(int i=0;i<p1.size();i++){
p2[i]+=p1[i];
}
return p2;
}
}
开发者ID:vipulharsh,项目名称:Coding,代码行数:14,代码来源:wto.cpp
示例11: graham
poly graham(poly p){
int i,j,n = p.size();
poly g;
pivo = *min_element(p.begin(), p.end(), cmp_pivo);
sort( p.begin(), p.end(), cmp_radial);
// n previous declared
for( i=j=0; i<n;i++){
while( j>=2 && ccw( g[j-2] , g[j-1], p[i]) >=0){
g.pop_back(); j--;
}
g.push_back(p[i]); j++;
}
return g;
}
开发者ID:dnr2,项目名称:maratona,代码行数:14,代码来源:10652+-+Board+Wrapping.cpp
示例12: subtract
inline poly subtract(poly &a, poly &b){
int N = (int)a.size(), M = (int)b.size();
int K = min(N, M);
poly ans;
if (N == 0 && M == 0)return ans;
ans.resize(max(N, M));
for (int i = 0; i < K; i++)ans[i] = a[i] - b[i];
for (int i = K; i < N; i++)ans[i] = a[i];
for (int i = K; i < M; i++)ans[i] = -b[i];
reduce(ans);
return ans;
}
开发者ID:lucassf,项目名称:UVA-Solutions,代码行数:15,代码来源:B.cpp
示例13: horner
std::pair<poly, cdouble> horner(const poly & a, const cdouble & x) {
int n = a.size();
poly b = poly(std::max(1, n - 1));
for (int i = n - 1; i > 0; i--)
b[i - 1] = a[i] + (i < n - 1 ? b[i] * x : 0);
return std::make_pair(b, a[0] + b[0] * x);
}
开发者ID:nikhiljangam,项目名称:Algorithms-Anthology,代码行数:7,代码来源:4.6.2+Complex+Root+Finding+(Laguerre's).cpp
示例14: multiply
inline poly multiply(poly &a, poly &b){
int N = (int)a.size(), M = (int)b.size();
poly ans;
if (N == 0 || M == 0)return ans;
ans.assign(N + M - 1, 0);
for (int i = 0; i < N; i++){
for (int j = 0; j < M; j++){
ans[i + j] += a[i] * b[j];
}
}
reduce(ans);
return ans;
}
开发者ID:lucassf,项目名称:UVA-Solutions,代码行数:16,代码来源:B.cpp
示例15: hull
poly hull( poly p ) {
int k = 0, n = p.size();
sort( p.begin(), p.end());
poly h( 2 * n );
for(int i = 0; i < n; i++){
while( k >= 2 && ccw( h[k-2], h[k-1], p[i] ) <= 0 ) k--;
h[ k++ ] = p[ i ];
}
int tmp = k + 1;
for(int i = n - 2; i >= 0; i--){
while( k >= tmp && ccw( h[k-2], h[k-1], p[i] ) <= 0 ) k--;
h[ k++ ] = p[ i ];
}
h.resize( k );
return h;
}
开发者ID:JoseMiguel,项目名称:icpc-training,代码行数:16,代码来源:uva811.cpp
示例16: derivative
poly derivative(const poly & p) {
int n = p.size();
poly r(std::max(1, n - 1));
for(int i = 1; i < n; i++)
r[i - 1] = p[i] * cdouble(i);
return r;
}
开发者ID:nikhiljangam,项目名称:Algorithms-Anthology,代码行数:7,代码来源:4.6.2+Complex+Root+Finding+(Laguerre's).cpp
示例17: dist
double dist( poly p ){
double res = 0;
for(int i = 0; i < p.size() - 1; i++){
res += dist( p[i], p[i + 1]);
}
return res;
}
开发者ID:JoseMiguel,项目名称:icpc-training,代码行数:7,代码来源:uva811.cpp
示例18: integrate
ld integrate(poly p){
ld res=0;
for(int i=0;i<p.size();i++){
res+=(p[i]/(i+1));
}
return res;
}
开发者ID:vipulharsh,项目名称:Coding,代码行数:7,代码来源:wto.cpp
示例19: eval
double eval(const poly &p, double x)
{
double ret = 0;
for (int i = (int)p.size() - 1; i >= 0; i--) {
ret = ret * x + p[i];
}
return ret;
}
开发者ID:EC-Ecstasy,项目名称:mithril,代码行数:8,代码来源:D.cpp
示例20: rotat
void rotat(poly &p)
{
poly q ;
for(int i=0;i<p.size();i++)
q.push_back((P){-p[i].y,p[i].x}) ;
normalize(q) ;
p=q ;
}
开发者ID:a00012025,项目名称:Online_Judge_Code,代码行数:8,代码来源:b382(2).cpp
注:本文中的poly类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论