本文整理汇总了C++中vd类的典型用法代码示例。如果您正苦于以下问题:C++ vd类的具体用法?C++ vd怎么用?C++ vd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了vd类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: gaussian_elimination
bool gaussian_elimination(vvd &matrix, vd &output) {
for (int i = 0; i < matrix.size(); i++) {
int pivot = find_pivot(matrix, i);
if (fabs(matrix[pivot][i]) < EPS) {
return false;
}
swap_row(matrix, pivot, i);
double factor = matrix[i][i];
for (int j = 0; j < matrix[i].size(); j++) {
matrix[i][j] /= factor;
}
for (int j = 0; j < matrix.size(); j++) {
if (j == i) {
continue;
}
factor = matrix[j][i];
for (int k = 0; k < matrix[j].size(); k++) {
matrix[j][k] -= factor*matrix[i][k];
}
}
}
output.clear();
for (int i = 0; i < matrix.size(); i++) {
output.push_back(matrix[i][matrix[i].size() - 1]);
}
return true;
}
开发者ID:toshihoge,项目名称:ACM-ICPC-Practice,代码行数:27,代码来源:d.cpp
示例2: SumSquaredDifferences
double SumSquaredDifferences( vd v, double avg)
{
vd::iterator it;
double sumSq = 0.0;
for(it = v.begin(); it < v.end(); ++it)
sumSq += pow(*it - avg,2.0);
return( sumSq );
}
开发者ID:olsonbg,项目名称:TraceHBonds,代码行数:10,代码来源:SimpleMath.cpp
示例3: Sum
double Sum( vd v)
{
vd::iterator it;
double sum = 0.0;
for(it = v.begin(); it < v.end(); ++it)
sum += *it;
return(sum);
}
开发者ID:olsonbg,项目名称:TraceHBonds,代码行数:10,代码来源:SimpleMath.cpp
示例4: conv
vd conv(vd a, vd b) {
int s = max(sz(a),sz(b)), L = get(s), n = 1<<L;
if (s <= 0) return {};
a.resize(n); a = fwht(a);
b.resize(n); b = fwht(b);
F0R(i,n) a[i] = a[i]*b[i];
a = fwht_rev(a);
return a;
}
开发者ID:benjame,项目名称:USACO,代码行数:11,代码来源:XOR+Convolution.cpp
示例5: average
double average( vd v)
{
vd::iterator it;
double sum = 0.0;
if ( v.size() == 0) return(0.0);
for(it = v.begin(); it < v.end(); ++it)
sum += *it;
return(sum/v.size());
}
开发者ID:olsonbg,项目名称:TraceHBonds,代码行数:12,代码来源:SimpleMath.cpp
示例6: solve
//a1x1+a2x2+a3=0
//b1x1+b2x2+b3=0
vctr solve(vd &a, vd &b)
{
assert(a.size()==b.size()&&a.size()==3);
if(fabs(b[0])>fabs(a[0]))swap(a,b);
assert(fabs(a[0])>EPS);
double k=b[0]/a[0];
rep(i,3)b[i]-=a[i]*k;
assert(fabs(b[1])>EPS);
double x2=-b[2]/b[1];
double x1=-(a[2]+a[1]*x2)/a[0];
return vctr(x1,x2);
}
开发者ID:Bobgy,项目名称:module,代码行数:14,代码来源:polygon.cpp
示例7: constructPoints
void constructPoints(const vector<Edge> &edges, const vd &mesh,
vector<Point> &points, vvi &edge2point) {
points.clear();
for (int x = 2; x <= 8; x += 2) {
for (int y = 2; y <= 8; y += 2) {
for (int z = 2; z <= 8; z += 2) {
D3 p(x, y, z);
if (isOneOfEndPoint(p, edges)) {
points.push_back(Point(p));
for (int i = 0; i < edges.size(); i++) {
if (edges[i].src == p) {
addPoint(points, edge2point, i);
} else if (edges[i].dst == p) {
addPoint(points, edge2point, i);
}
}
}
}
}
}
for (int i = 0; i < edges.size(); i++) {
D3 p = edges[i].src;
D3 v = edges[i].dst - edges[i].src;
for (int j = 0; j < mesh.size(); j++) {
points.push_back(Point(p + mesh[j]*v));
addPoint(points, edge2point, i);
}
}
}
开发者ID:toshihoge,项目名称:ACM-ICPC-Practice,代码行数:29,代码来源:j2.cpp
示例8: stddev
double stddev( vd v, double avg)
{
vd::iterator it;
double sumSq = SumSquaredDifferences(v, avg);
return( stddev(sumSq,v.size()) );
}
开发者ID:olsonbg,项目名称:TraceHBonds,代码行数:7,代码来源:SimpleMath.cpp
示例9: getDualProblem
void getDualProblem(const vvd& a, vd& b, vd& c, vvd& dual_a, vd& dual_b, vd& dual_c)
{
for (auto x : b)
{
dual_c.push_back(-x);
}
for (auto x : c)
{
dual_b.push_back(-x);
}
dual_a.assign(a[0].size(), vd());
for (size_t i = 0; i < a.size(); ++i)
{
for (size_t j = 0; j < a[i].size(); ++j)
{
dual_a[j].push_back(-a[i][j]);
}
}
}
开发者ID:AntonGitName,项目名称:MathematicalOptimizationLabs,代码行数:19,代码来源:main.cpp
示例10: main
int main() {
ios::sync_with_stdio(0);
while(cin >> n >> p && n) {
po.assign(n + 1, 1);
for(int i = 1; i <= n; i++) po[i] = po[i - 1] * p;
memo.assign(n + 1, vd(n + 1, -1));
cout << fixed << setprecision(10) << solve(0, n) << endl;
}
return 0;
}
开发者ID:mehranagh20,项目名称:uvaSolvedPromblems,代码行数:12,代码来源:11176-Winning-Streak.cpp
示例11: dfs
void dfs(vvid &adj, int fr, int to, vd path, vb &vis){
vis[fr] = 1;
if (fr == to){
for (double e : path)
res = max(res, e);
return;
}
for (int i=0;i<adj[fr].size();i++){
if (!vis[adj[fr][i].first]){
path.push_back(adj[fr][i].second);
dfs(adj, adj[fr][i].first, to, path, vis);
}
}
return;
}
开发者ID:marbrb,项目名称:practice-contest,代码行数:15,代码来源:534.cpp
示例12: printTask
void printTask(const vvd& a, const vd& b, const vd& c, const std::string& filename = "task.txt")
{
size_t n = c.size();
size_t m = a.size();
std::ofstream out(filename);
for (size_t i = 0; i < n; ++i)
{
auto& t = c[i];
if (std::abs(t) < EPS)
{
continue;
}
if (t > 0)
{
out << "+\t" << t;
}
if (t < 0)
{
out << "-\t" << -t;
}
out << " * x" << i + 1 << "\t";
}
out << "-----> MAX\n";
for (size_t i = 0; i < m; ++i)
{
out << "x" << n + i + 1 << "\t=\t" << b[i] << "\t";
for (size_t j = 0; j < n; ++j)
{
auto t = -a[i][j];
if (std::abs(t) < EPS)
{
continue;
}
if (t > 0)
{
out << "+\t" << t;
}
if (t < 0)
{
out << "-\t" << -t;
}
out << " * x" << j + 1 << "\t";
}
out << endl;
}
}
开发者ID:AntonGitName,项目名称:MathematicalOptimizationLabs,代码行数:46,代码来源:main.cpp
示例13: operator
double pcet::operator()(const vd& v) {
double xn1 = v[1],pn1 = v[2],xn2 = v[3],pn2 = v[4],qr = v[5],pr = v[6];
double n1=e.n(xn1,pn1),n2=e.n(xn2,pn2);
double h_bath=0.0;
for (size_t i = 7; i < v.size(); ++(++i)) {
size_t ib=(i-7)/2;
double mw2=bp.m*pow(bw[ib],2);
h_bath+= v[i+1]*v[i+1]*0.5/bp.m
+ mw2*0.5*pow((v[i]+n1*bc[ib]/mw2),2);
}
double h11 = sp.eps_r + sp.w_r*sp.w_r*sp.m*pow((qr-sp.qr_initial),2)*0.5;
double h22 = sp.eps_k + sp.w_k*sp.w_k*sp.m*pow((qr-sp.qr_initial),2)*0.5;
double h12 = sp.delta;
double h_avg= (h11+h22)*0.5;
double h_delta= h11-h22;
return pr*pr*0.5/sp.m+
h_avg+
h_delta*(n1-n2)*0.5+
sp.delta*(xn1*xn2+pn1*pn2) + h_bath;
//2*delta*sqrt((n1+e.n_shift)*(n2+e.n_shift))*(xn1*xn2+pn1*pn2); ///> TODO
}
开发者ID:kirilligum,项目名称:qcmm,代码行数:21,代码来源:pcet.cpp
示例14: print
void print(const vd &a){rep(i,a.size())printf("%.2lf%c",a[i],i==a.size()-1?'\n':' ');}
开发者ID:Bobgy,项目名称:module,代码行数:1,代码来源:polygon.cpp
示例15: bitstream
vi bitstream(vd in)
{
vi out(in.size());
for (int n=0; n<in.size(); n++) {out[n]=(copysign(1,in[n])+1)/2;}
return out;
}
开发者ID:tbickle,项目名称:comm_simulations,代码行数:6,代码来源:comm.cpp
示例16: fwht_rev
vd fwht_rev(vd& a) {
vd res = fwht(a);
F0R(i,sz(res)) res[i] /= a.size();
return res;
}
开发者ID:benjame,项目名称:USACO,代码行数:5,代码来源:XOR+Convolution.cpp
示例17: BellmanFordMoore
//shortest path from a node n to every other node:
//this is for any graphs even ones that have negative weights -- can detect negative cycles
//for every vertex, relax E times
//as an optimization we use a queue to store vertices that changed
//and relax paths only from that queue
//to detect negative loops can check if node n gets updated on any the n-th iteration
int BellmanFordMoore(const graphtp & g, vd & D, int src)
{
int comparisons = 0;
vi visited(g.size());
std::vector<edge> P(g.size()); //parent node for node e.to is e.from
for(vd::iterator it = D.begin(); it != D.end(); ++it)
*it = INFINITY;
D[src] = 0;
si lastupdated;
//keep a queue (set) of vertices (nodes) that were updated last time around
//do the relaxation V times
for(size_t i = 0; i < g.size(); i++) {
lastupdated.insert(i);
}
//without optimization loop would be: for(int i = 0; i < g.size(); i++)
size_t counter = 0;
while(!lastupdated.empty()) {
counter++;
si newlast;
//visit and relax all edges (two for loopxs needed to visit all edges)
for(si::iterator jt = lastupdated.begin();jt != lastupdated.end(); jt++)
{
int v = *jt;
out("next to work on is %d\n", v);
for(ve::const_iterator it = g[v].begin(); it != g[v].end(); ++it)
{
float dist = D[v] + it->weight;
assert(v == it->from && "not the same node");
if(D[it->to] > dist) { //this is the relaxation step
out("counter %d, it->to %d\n", counter, it->to);
if(counter >= g.size()) {
//we should not update a node in a stage greater than sz
printf("negative cycles exists distance %d to %d is %f\n", v, it->to, dist);
//need to trace back from P[v]
//printSP(P, it->to, v);
printSP(P, v, it->to);
printf("\n");
return -1;
}
D[it->to] = dist;
P[it->to] = *it;
newlast.insert(it->to); //track which changed
out("new distance %d to %d is %f\n", v, it->to, dist);
}
}
}
lastupdated = newlast;
}
for(size_t i = 0; i < D.size(); i++) {
printf("%d -> %d sp=%.2f ", src, i, D[i]);
printSP(P, i, src);
printf("\n");
}
out("comparisons %d\n", comparisons);
return 0;
}
开发者ID:uriqishtepi,项目名称:uvaonlinejudge,代码行数:68,代码来源:graph_sp_allpairs_johnsons.cpp
示例18: printResult
void printResult(vd &v){
int n = v.size();
printf("Xn: Yn:\n");
for(int i=0; i<n; i++)
printf("%.2f %.4f\n", v[i].first, v[i].second);
}
开发者ID:mtreviso,项目名称:university,代码行数:6,代码来源:Trabalho15.cpp
示例19: normalise
void normalise(vd & v, int j)
{
double x = v[j];
range(k, j, v.size()) v[k] /= x;
}
开发者ID:JustinLovesCompsci,项目名称:competitions,代码行数:5,代码来源:blur.cpp
示例20: zero_out
void zero_out(vd & v, vd & u, int j)
{
if(zero(u[j])) return;
double r = u[j] / v[j];
range(k, j, v.size()) u[k] -= r * v[k];
}
开发者ID:JustinLovesCompsci,项目名称:competitions,代码行数:6,代码来源:blur.cpp
注:本文中的vd类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论