本文整理汇总了C++中seg类的典型用法代码示例。如果您正苦于以下问题:C++ seg类的具体用法?C++ seg怎么用?C++ seg使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了seg类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ask
data ask(int _l,int _r)
{
if ( _l > rt || _r < lt )
return data();
if ( _l <= lt && rt <= _r )
return x;
int md = (lt+rt)/2;
if ( l == NULL ) l = new seg(lt,md);
if ( r == NULL ) r = new seg(md+1,rt);
return l->ask(_l,_r) + r->ask(_l,_r);
}
开发者ID:danalex97,项目名称:Codeforces,代码行数:14,代码来源:tt.cpp
示例2: contains
int
plane::
contains ( const seg& segIn ) const
{
vec3 pos ( math::vec3::NoInit );
vec3 dir ( math::vec3::NoInit );
ValueType len;
segIn.get ( pos, dir, len );
// dir.normalize ();
// vec3 endPos = pos + dir * len;
vec3 endPos ( dir );
endPos *= len;
endPos += pos;
int c1 = contains ( pos );
int c2 = contains ( endPos );
if ( c1 )
{
if ( c2 )
return containsResult::AllIn | containsResult::SomeIn;
return containsResult::SomeIn;
}
if ( c2 )
{
return containsResult::SomeIn;
}
return containsResult::NoneIn;
}
开发者ID:prwhite,项目名称:philibs,代码行数:32,代码来源:pniplane.cpp
示例3: update
void update(int p,data v)
{
if ( lt == rt )
{
x = v;
return;
}
int md = (lt+rt)/2;
if ( l == NULL ) l = new seg(lt,md);
if ( r == NULL ) r = new seg(md+1,rt);
if ( p <= md )
l->update(p,v);
else
r->update(p,v);
x = l->x + r->x;
}
开发者ID:danalex97,项目名称:Codeforces,代码行数:18,代码来源:tt.cpp
示例4: print
void print(int all)
{
if ( all )
{
cerr<<lt<<' '<<rt<<' ';
x.print('\n');
}
if ( lt == rt )
{
if ( !all ) x.print(' ');
return;
}
int md = (lt + rt)/2;
if ( l == NULL ) l = new seg(lt,md);
if ( r == NULL ) r = new seg(md+1,rt);
l->print(all);
r->print(all);
}
开发者ID:danalex97,项目名称:Codeforces,代码行数:21,代码来源:tt.cpp
示例5: contains
int
seg::
contains ( const seg& segIn ) const
{
// TODO: Remove direction vector normalization?? User's responsibility???
vec3 tDir ( segIn.dir );
tDir.normalize ();
// vec3 endPt = segIn.pos + tDir * segIn.length;
vec3 endPt ( tDir );
endPt *= segIn.length;
endPt += segIn.pos;
int c1 = contains ( segIn.pos );
int c2 = contains ( endPt );
if ( c1 )
{
if ( c2 )
return containsResult::AllIn;
return containsResult::SomeIn;
}
if ( c2 )
return containsResult::SomeIn;
// OPTIMIZE: Expensive...
if ( segIn.contains ( pos ) )
return containsResult::SomeIn;
vec3 endPos = pos + dir * length;
if ( segIn.contains ( endPos ) )
return containsResult::SomeIn;
return containsResult::NoneIn;
}
开发者ID:prwhite,项目名称:philibs,代码行数:38,代码来源:pniseg.cpp
示例6: extendBy
void
plane::
extendBy ( const seg& segIn )
{
vec3 pos ( math::vec3::NoInit );
vec3 dir ( math::vec3::NoInit );
ValueType len;
segIn.get ( pos, dir, len );
// dir.normalize ();
// dir = pos + dir * len;
dir *= len;
dir += pos;
extendBy ( pos );
extendBy ( dir );
}
开发者ID:prwhite,项目名称:philibs,代码行数:15,代码来源:pniplane.cpp
示例7: xform4
void
seg::
xform4 ( const seg& seg, const matrix4& mat )
{
PNIMATHUNTESTED;
// get endpoint of seg
vec3 end ( math::vec3::NoInit );
seg.lerp ( end, TraitType::oneVal );
// xform seg's beginning and ending
end.xformPt4 ( end, mat );
pos.xformPt4 ( seg.pos, mat );
// finish making this seg
// the following code is equivalent to: set ( pos, end );
// but it doesn't redundantly set pos again
dir = end;
dir -= pos;
length = dir.length ();
dir /= length;
}
开发者ID:prwhite,项目名称:philibs,代码行数:24,代码来源:pniseg.cpp
示例8: get_y
bool operator < (const seg &a) const {
ld x = max(min(p.x, q.x), min(a.p.x, a.q.x));
return get_y(x) < a.get_y(x) - eps;
}
开发者ID:slava-sh,项目名称:code-plagiarism-detector,代码行数:4,代码来源:002840-open-2015-206-Cyan.cpp
示例9: contains
// OPTIMIZE: This is a HUGE/heavyweight function. Probably several ways to optimize it.
int
sphere::
contains ( const seg& segIn ) const
{
vec3 pos;
vec3 dir;
ValueType len;
segIn.get ( pos, dir, len );
dir.normalize ();
vec3 endPos = pos + dir * len;
// The segment begin and endpoint might lie in the sphere.
int c1 = contains ( pos );
int c2 = contains ( endPos );
if ( c1 )
{
if ( c2 )
return containsResult::AllIn | containsResult::SomeIn;
return containsResult::SomeIn;
}
if ( c2 )
{
return containsResult::SomeIn;
}
ValueType a = dir.dot ( dir );
//ValueType a = dir.vec[0] * dir.vec[0] + dir.vec[1] * dir.vec[1] + dir.vec[2] * dir.vec[2];
ValueType b = static_cast< ValueType > ( 2.0 ) * dir.vec[0] * ( pos.vec[0] - center.vec[0] ) +
static_cast< ValueType > ( 2.0 ) * dir.vec[1] * ( pos.vec[1] - center.vec[1] ) +
static_cast< ValueType > ( 2.0 ) * dir.vec[2] * ( pos.vec[2] - center.vec[2] );
ValueType tx = pos.vec[0] - center.vec[0];
ValueType ty = pos.vec[1] - center.vec[1];
ValueType tz = pos.vec[2] - center.vec[2];
ValueType c = tx * tx + ty * ty + tz * tz - radius * radius;
//ValueType c = ( pos.vec[0] - center.vec[0] ) * ( pos.vec[0] - center.vec[0] ) +
// ( pos.vec[1] - center.vec[1] ) * ( pos.vec[0] - center.vec[0] ) +
// ( pos.vec[0] - center.vec[0] ) * ( pos.vec[0] - center.vec[0] ) -
// radius * radius;
// Check the discriminant to see if there are any solutions.
ValueType discriminant = b * b - static_cast< ValueType > ( 4.0 ) * a * c;
if ( discriminant < TraitType::zeroVal )
{
// No solutions --> no intersections.
return containsResult::NoneIn;
}
ValueType twoA = static_cast< ValueType > ( 2.0 ) * a;
if ( discriminant == TraitType::zeroVal )
{
// One intersection. Segment is tangential.
ValueType t1 = -b / twoA;
vec3 ip1 = pos + dir * t1;
return segIn.contains ( ip1 );
}
// Two intersections.
ValueType t1 = ( -b + TraitType::sqrt ( discriminant ) ) / twoA;
ValueType t2 = ( -b - TraitType::sqrt ( discriminant ) ) / twoA;
vec3 ip1 = pos + dir * t1;
vec3 ip2 = pos + dir * t2;
if ( segIn.contains ( ip1 ) || segIn.contains ( ip2 ) )
return containsResult::SomeIn;
else
return containsResult::NoneIn;
}
开发者ID:prwhite,项目名称:philibs,代码行数:75,代码来源:pnisphere.cpp
示例10: main
int main()
{
ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
ifstream F("p.in");
#endif
F>>n>>m;
for (int i=1,x,y;i<=n;++i)
{
F>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
try
{
find_cycle(1);
}
catch (pair<int,int> p)
{
int x = p.first;
int y = p.second;
cyc.push_back(y);
while ( x != y )
{
cyc.push_back(x);
x = dd[x];
}
}
for (int i=0;i<int(cyc.size());++i)
ord[cyc[i]] = i+1;
//for (int i=0;i<int(cyc.size());++i) cerr<<cyc[i]<<' '; cerr<<'\n';
memset(mk,0,sizeof(mk));
memset(dd,0,sizeof(dd));
for (int i=0;i<int(cyc.size());++i)
mk[cyc[i]] = 1;
for (int i=0;i<int(cyc.size());++i)
{
act_tree = i;
find_chains(cyc[i]);
}
for (int i=0;i<int(chains.size());++i)
for (int j=0;j<int(chains[i].size());++j)
{
int x = chains[i][j];
my[x] = i;
pl[x] = j+1;
}
//for (int i=0;i<int(chains.size());++i,cerr<<'\n') { cerr<<i<<':'; for (int j=0;j<int(chains[i].size());++j) cerr<<chains[i][j]<<' '; }
for (int i=0;i<int(chains.size());++i)
{
s[i] = seg(chains[i].size());
s[i].build(1,1,chains[i].size());
}
c = seg(cyc.size());
c.build(1,1,cyc.size());
ans = n;
//for (int i=1;i<=n;++i) cerr<<dd[i]<<' '; cerr<<'\n';
//for (int i=1;i<=n;++i) cerr<<my[i]<<' '; cerr<<'\n';
//for (int i=1;i<=n;++i) cerr<<pl[i]<<' '; cerr<<'\n';
for (int q=1,x,y;q<=m;++q)
{
F>>x>>y;
//cerr<<x<<' '<<y<<'\n';
vector<int> ax,ay;
for (int i=x;;i=dd[i])
{
i = chains[my[i]].back();
ax.push_back(my[i]);
if ( !dd[i] ) break;
}
for (int i=y;;i=dd[i])
{
i = chains[my[i]].back();
//cerr<<i<<'\n';
ay.push_back(my[i]);
if ( !dd[i] ) break;
}
reverse(ax.begin(),ax.end());
reverse(ay.begin(),ay.end());
ax.resize(ax.size()+1);
ax[ax.size()-1] = -1;
ay.resize(ay.size()+1);
ay[ay.size()-1] = -2;
int mx = max(ax.size(),ay.size());
ax.resize(mx);
ay.resize(mx);
//for (int i=0;i<int(ax.size());++i) cerr<<ax[i]<<' '; cerr<<'\n';
//for (int i=0;i<int(ay.size());++i) cerr<<ay[i]<<' '; cerr<<'\n';
if ( tree[x] == tree[y] )
//.........这里部分代码省略.........
开发者ID:danalex97,项目名称:Codeforces,代码行数:101,代码来源:tractor1.cpp
示例11:
/** Get the ordering of the segments after the cur_x value
* choose the extra x needed for arrangement accordingly.
*/
bool operator< (const seg & a, const seg & b) {
return a.get_y(cur_x+1e-8) < b.get_y(cur_x+1e-8);
}
开发者ID:jaigupta,项目名称:algorithmic-arena,代码行数:6,代码来源:lineintersection.cpp
示例12: solve2
void solve2(int l,int r)
{
int n = cyc.size();
ans -= c.ask(1,1,n,l,r);
//cerr<<ans<<' ';
c.update(1,1,n,l,r);
ans += c.ask(1,1,n,l,r);
//cerr<<ans<<'\n';
}
开发者ID:danalex97,项目名称:Codeforces,代码行数:10,代码来源:tractor1.cpp
示例13: main
int main () {
scanf("%d", &n);
tree.build(1, 0, n);
while (scanf("%d %d %d", &k, &a, &b) != EOF) {
if (k == 1) {
scanf("%d", &v);
tree.add(1, a-1, b, v);
} else {
printf("%d\n", tree.getVal(1, a-1, b));
}
}
}
开发者ID:victorsenam,项目名称:treinos-old,代码行数:12,代码来源:segtree.cpp
示例14: main
int main () {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
tree.criaAcc(n);
tree.build(1, 0, n);
scanf("%d", &q);
for (int i = 0; i < q; i++) {
scanf("%d %d", &a, &b);
tree.res = tree.getQuery(1, a-1, b);
printf("%d %d\n", tree.acc[tree.res.fm] - tree.acc[tree.res.im], tree.res.fm - tree.res.im);
}
}
}
开发者ID:victorsenam,项目名称:treinos-old,代码行数:15,代码来源:banfarao.cpp
示例15: main
int main () {
scanf("%d", &tc);
for (int t = 1; t <= tc; t++) {
scanf("%d %d", &n, &q);
printf("Scenario #%d:\n", t);
for (int i = 0; i < n; i++)
scanf("%d", inp+i);
tree.build(1, 0, n);
int lo, hi;
for (int i = 0; i < q; i++) {
scanf("%d %d", &lo, &hi);
printf("%d\n", tree.query(lo-1, hi).v);
}
}
}
开发者ID:victorsenam,项目名称:treinos,代码行数:19,代码来源:nolazy.cpp
示例16: main
int main(int argc, char *argv[])
{
scanf("%d%d",&k,&s);
for(int i = 1;i<=k;i++){
scanf("%d%d",&p[i+1].l,&p[i+1].r);
p[i+1].l += d;
p[i+1].r += d;
}
for(int i = 1;i<=k;i++)
{
int l = o.f(p[i+1].l);
int r = o.f(p[i+1].r);
if(l == 0)
f[i+1][1] = p[i+1].l*2;
else
f[i+1][1] = min(f[l][1]+abs(p[l].l-p[i+1].l),f[l][2]+abs(p[l].r-p[i+1].l));
o.b(p[i+1].l,p[i+1].r,i);
}
system("PAUSE");
return EXIT_SUCCESS;
}
开发者ID:niyuzheno1,项目名称:CODES,代码行数:21,代码来源:Ans.cpp
示例17: main
int main () {
scanf("%d %d", &n, &m);
tree.build(1, 0, n);
for (int i = 0; i < m; i++) {
scanf("%d %d %d", &a, &b, &x);
if (a == x) {
tree.update(1, a, b, x);
} else if (b == x) {
tree.update(1, a-1, b-1, x);
} else {
tree.update(1, a-1, x-1, x);
tree.update(1, x, b, x);
}
}
tree.printit(1, 0);
printf("\n");
}
开发者ID:victorsenam,项目名称:treinos-old,代码行数:17,代码来源:P8.cpp
注:本文中的seg类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论