você não especificou nenhum destinatário

Você tem certeza de que deseja enviar uma mensagem sem assunto?

Archive for the ‘C++’ Category

Bjarne Stroustrup: C++14 Early Thoughts (video)

leave a comment »

Bjarne Stroustrup discusses features that might appear in C++14: braces for copy initialization, return type deduction in functions, generic (polymorphic) lambdas, user-defined literals, etc.

C++14 Early Thoughts

Outros artigos:

Herb Sutter – The Future of C++
Bjarne Stroustrup – C++11 Style

Written by Ciro Cavani

2013-10-11 at 9:10 pm

Publicado em C++, Software Development, Video

Tagged with

Machine Learning – Referências

with 5 comments

Esse artigo é sobre Machine Learning, links relevantes e plataformas interessantes.

Nesse estudo, apresento alguns recursos que acredito sejam relevantes em Machine Learning. O foco foi no contexto geral sobre a área e plataformas relacionadas com linguagens de programação mais conhecidas.

Última Atualização: 17/04/2013 (publicação)

Conteúdo:

Referência
Software



Referência

Machine Learning
http://en.wikipedia.org/wiki/Machine_learning
Machine learning, a branch of artificial intelligence, is about the construction and study of systems that can learn from data. The core of machine learning deals with representation and generalization. Representation of data instances and functions evaluated on these instances are part of all machine learning systems. Generalization is the property that the system will perform well on unseen data instances; the conditions under which this can be guaranteed are a key object of study in the subfield of computational learning theory.

ACM Transactions on Intelligent Systems and Technology
http://tist.acm.org/
ACM Transactions on Intelligent Systems and Technology (ACM TIST) is a new scholarly journal that publishes the highest quality papers on intelligent systems, applicable algorithms and technology with a multi-disciplinary perspective. An intelligent system is one that uses artificial intelligence (AI) techniques to offer important services (e.g., as a component of a larger system) to allow integrated systems to perceive, reason, learn, and act intelligently in the real world.

The Journal of Machine Learning Research
http://jmlr.org/
The Journal of Machine Learning Research (JMLR) provides an international forum for the electronic and paper publication of high-quality scholarly articles in all areas of machine learning. All published papers are freely available online.

Course | Machine Learning by Stanford University
http://www.youtube.com/playlist?list=PLA89DCFA6ADACE599
Lecture by Professor Andrew Ng for Machine Learning (CS 229) in the Stanford Computer Science department.

Machine Learning by mathematicalmonk’s channel
http://www.youtube.com/playlist?list=PLD0F06AA0D2E8FFBA

http://research.yahoo.com/Machine_Learning
http://research.google.com/pubs/MachineLearning.html
http://research.google.com/pubs/ArtificialIntelligenceandMachineLearning.html
http://research.microsoft.com/en-us/about/our-research/machine-learning.aspx

Kaggle
http://www.kaggle.com/
Kaggle is the leading platform for predictive modeling competitions. Companies, governments and researchers present datasets and problems – the world’s best data scientists then compete to produce the best solutions. At the end of a competition, the competition host pays prize money in exchange for the intellectual property behind the winning model.

Machine Learning Open Source Software
http://jmlr.org/mloss
To support the open source software movement, JMLR MLOSS publishes contributions related to implementations of non-trivial machine learning algorithms, toolboxes or even languages for scientific computing.
http://mloss.org/
Forum for open source software in machine learning.

Machine Learning | Coursera
https://www.coursera.org/course/ml
This course provides a broad introduction to machine learning, datamining, and statistical pattern recognition.



Software

http://en.wikipedia.org/wiki/Category:Data_mining_and_machine_learning_software

GNU/Linux AI & Alife HOWTO
http://www.tldp.org/HOWTO/AI-Alife-HOWTO-7.html
Libraries or frameworks used for writing machine learning systems.

(Java)

Apache Mahout
http://mahout.apache.org/
http://en.wikipedia.org/wiki/Apache_Mahout
Mahout’s goal is to build scalable machine learning libraries. The core algorithms for clustering, classification and batch based collaborative filtering are implemented on top of Apache Hadoop using the map/reduce paradigm (However Mahout do not restrict contributions to Hadoop based implementations).

Introducing Apache Mahout
http://www.ibm.com/developerworks/java/library/j-mahout/
Mahout co-founder Grant Ingersoll introduces the basic concepts of machine learning and then demonstrates how to use Mahout to cluster documents, make recommendations, and organize content.

Apache Mahout: Scalable machine learning for everyone
http://www.ibm.com/developerworks/java/library/j-mahout-scaling/
Apache Mahout committer Grant Ingersoll brings you up to speed on the current version of the Mahout machine-learning library and walks through an example of how to deploy and scale some of Mahout’s more popular algorithms.

Weka
http://www.cs.waikato.ac.nz/ml/weka/
http://en.wikipedia.org/wiki/Weka_(machine_learning)
Weka is a collection of machine learning algorithms for data mining tasks. The algorithms can either be applied directly to a dataset or called from your own Java code. Weka contains tools for data pre-processing, classification, regression, clustering, association rules, and visualization. It is also well-suited for developing new machine learning schemes.

(Python)

Scikit-learn
http://scikit-learn.org/
http://en.wikipedia.org/wiki/Scikit-learn
Scikit-learn integrates machine learning algorithms in the tightly-knit scientific Python world, building upon numpy, scipy, and matplotlib. As a machine-learning module, it provides versatile tools for data mining and analysis in any field of science and engineering.

Orange
http://orange.biolab.si/
http://en.wikipedia.org/wiki/Orange_(software)

(C++)

GraphLab
http://graphlab.org/
GraphLab is a graph-based, high performance, distributed computation framework written in C++. While GraphLab was originally developed for Machine Learning tasks, it has found great success at a broad range of other data-mining tasks; out-performing other abstractions by orders of magnitude.

mlpack
http://www.mlpack.org/
mlpack is a C++ machine learning library with emphasis on scalability, speed, and ease-of-use. Its aim is to make machine learning possible for novice users by means of a simple, consistent API, while simultaneously exploiting C++ language features to provide maximum performance and maximum flexibility for expert users.

Waffles
http://waffles.sourceforge.net/
http://en.wikipedia.org/wiki/Waffles_(machine_learning)

(API)

Google Prediction API
https://developers.google.com/prediction/
Google’s cloud-based machine learning tools can help analyze your data to add the following features to your applications: Customer sentiment analysis, Spam detection, Message routing decisions, Upsell opportunity analysis, Document and email classification, Diagnostics, Churn analysis, Suspicious activity identification, Recommendation systems

Written by Ciro Cavani

2013-04-17 at 10:52 pm

Publicado em C++, Java, Python, Software Development

Tagged with

Herb Sutter – The Future of C++

with one comment

This talk will give an update on recent progress and near-future directions for C++, both at Microsoft and across the industry, with some announcements of interest in both areas. The speaker is the lead language architect of Visual C++ and chair of the ISO C++ committee.

Herb Sutter - The Future of C++

http://channel9.msdn.com/Events/Build/2012/2-005

C++
http://en.wikipedia.org/wiki/C++
http://en.wikipedia.org/wiki/C++11

C++ (pronounced “see plus plus”) is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. Developed by Bjarne Stroustrup starting in 1979 at Bell Labs, it adds object oriented features, such as classes, and other enhancements to the C programming language.

The Design and Evolution of C++
http://www.stroustrup.com/dne.html

Written by Bjarne Stroustrup, the designer of C++, this book presents the definitive insider’s guide to the design and development of the C++ programming language. Without omitting critical details or getting bogged down in technicalities, Stroustrup presents his unique insights into the decisions that shaped C++. Every C++ programmer will benefit from Stroustrup’s explanations of the ‘why’s’ behind the language.

Standard C++
http://isocpp.org/

The home of Standard C++ on the web — news, status and discussion about the C++ standard on all compilers and platforms.

Standard C++ Foundation is a Washington 501(c)(6) not-for-profit organization whose purpose is to support the C++ software developer community and promote the understanding and use of modern Standard C++ on all compilers and platforms.

In particular, two near-term goals of that mission are:

  1. To promote dissemination of correct and up-to-date information about modern C++.
  2. To promote greater availability of high-quality C++ libraries, including both standard libraries (by reducing barriers to submitting and adopting libraries in Standard C++ itself) and community libraries (by having an organized, and ideally tool-supported, way for C++ developers to discover and use libraries).

GCC, the GNU Compiler Collection
http://gcc.gnu.org/
http://en.wikipedia.org/wiki/GNU_Compiler_Collection

The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages. GCC has been ported to a wide variety of processor architectures, and is widely deployed.

C++11 Support in GCC
http://gcc.gnu.org/projects/cxx0x.html
http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011

(switching GCC’s implementation language to C++)
http://gcc.gnu.org/wiki/gcc-in-cxx
http://gcc.gnu.org/wiki/cxx-conversion

LLVM Clang
http://clang.llvm.org/
http://llvm.org/
http://en.wikipedia.org/wiki/Clang
http://en.wikipedia.org/wiki/LLVM

The goal of the Clang project is to create a new C, C++, Objective C and Objective C++ front-end for the LLVM compiler. LLVM (formerly Low Level Virtual Machine) is compiler infrastructure written in C++; it is designed for compile-time, link-time, run-time, and “idle-time” optimization of programs written in arbitrary programming languages. Originally implemented for C and C++, the language-agnostic design (and the success) of LLVM has since spawned a wide variety of front ends.

Boost C++ Libraries
http://www.boost.org/
Boost provides free peer-reviewed portable C++ source libraries.

POCO C++ Libraries
http://pocoproject.org/
Modern, powerful open source C++ class libraries and frameworks for building network- and internet-based applications that run on desktop, server, mobile and embedded systems.

Facebook Folly
https://github.com/facebook/folly
Folly is an open-source C++ library developed and used at Facebook.

Outros Artigos

Bjarne Stroustrup – C++11 Style
https://cirocavani.wordpress.com/2012/02/17/bjarne-stroustrup-c11-style/

This presentation reflects my thoughts on what “Modern C++” should mean in the 2010s: a language for programming based on light-weight abstraction with direct and efficient mapping to hardware, suitable for infrastructure code.

Written by Ciro Cavani

2012-11-24 at 12:46 pm

Publicado em C++, Video

107 – The Cat in the Hat

leave a comment »

107 – The Cat in the Hat (pdf)

http://github.com/cirocavani/uva.onlinejudge.org-cxx/tree/master/107

#include <iostream>
#include <vector>
#include <cmath>

struct V
{
  double h, m, k, n;
  V(double _h, double _m) : h(_h), m(_m), k(0.0), n(0.0) { }

  void operator()()
  {
    if (m == 1.0)
      {
	k = std::log(h) / std::log(2.0);
	n = 1.0;
      }
    else if (h - m == 1.0)
      {
	k = 1.0;
	n = m;
      }
    else
      {
	for (double _k = 2.0, mk = std::log(h) / std::log(2.0); _k < mk; ++_k)
	  {
	    double kr = 1.0 / _k;

	    double _nm = std::pow(m, kr);

	    double _nh = std::pow(h, kr) - 1.0;

	    if (std::abs(_nh - _nm) < 0.01)
	      {
		k = _k;
		n = _nm;
		break;
	      }
	  }
      }
  }

  double ms() const
  {
    return n == 1.0 ? k : (std::pow(n, k) - 1.0) / (n - 1.0);
  }
  double hs() const
  {
    double q = n / (n + 1.0);
    return h * (std::pow(q, k) - 1.0) / (q - 1.0) + m;
  }
};

class W
{
  std::vector<V> v;
public:
  W() { }
  inline friend std::istream& operator>>(std::istream& in, W& w)
  {
    double h, m;
    in >> h >> m >> std::ws;

    if (h == 0 && m == 0)
      {
	in.setstate(std::ios::eofbit);
	return in;
      }

    w.v.push_back(V(h, m));
    
    return in;
  }
  inline friend std::ostream& operator<<(std::ostream& out, const W& w)
  {
    out.precision(0);
    for (std::vector<V>::const_iterator i = w.v.begin(); i != w.v.end(); ++i)
      {
	out << std::fixed << i->ms();
	out << " ";
	out << std::fixed << i->hs();
	out << std::endl;
      }
    return out;
  }
  inline void operator()()
  {
    for (std::vector<V>::iterator i = v.begin(); i != v.end(); ++i)
      (*i)();
  }
};

int main()
{
  W w;

  while (std::cin.good())
    std::cin >> w;

  w();

  std::cout << w;

  return 0;
}

Written by Ciro Cavani

2012-10-20 at 12:24 pm

Publicado em C++, Puzzle

106 – Fermat vs. Pythagoras

leave a comment »

106 – Fermat vs. Pythagoras (pdf)

http://github.com/cirocavani/uva.onlinejudge.org-cxx/tree/master/106

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>

const int N_MAX = 1000000;

inline int gcd(int a, int b)
{
  int t;
  while (b != 0)
    {
      t = b;
      b = a % b;
      a = t;
    }
  return a;
}

struct V
{
  int n, p, q;
  V(int _n)
    : n(_n), p(0), q(_n) { }
  inline void operator()(int _p, int _q)
  {
    p = _p;
    q -= _q;
  }
};

struct T
{
  int c, b, a;
  bool prime;
  T(int _c, int _b, int _a, bool _p = false)
    : c(_c), b(std::max(_a,_b)), a(std::min(_a,_b)), prime(_p) { }
  inline bool operator<(const T& o) const
  {
    return c < o.c;
  }
  inline T operator*(int k) const
  {
    return T(k * c, k * b, k * a);
  }
};

struct Q
{
private:
  std::vector<bool> v;
  int _size;
  inline void count(int i)
  {
    if (v[i])
      return;
 
    v[i] = true;
    ++_size;
  }
public:
  Q() : _size(0), v(N_MAX + 1, false) { }
  inline int size() const
  {
    return _size;
  }
  inline void operator+=(const T& t)
  {
    count(t.a);
    count(t.b);
    count(t.c);
  }
};

class W
{
  std::vector<int> u;
  std::map<int, V> v;
  int ux;
public:
  W() : ux(0) { }
  inline friend std::istream& operator>>(std::istream& in, W& w)
  {
    int n;
    in >> n >> std::ws;

    w.u.push_back(n);
    w.v.insert(std::make_pair(n, V(n)));

    if (n > w.ux)
      w.ux = n;

    return in;
  }
  inline friend std::ostream& operator<<(std::ostream& out, const W& w)
  {
    for (std::vector<int>::const_iterator i = w.u.begin(); i != w.u.end(); ++i)
      {
	const V& vn = w.v.find(*i)->second; 
	out << vn.p << " " << vn.q << std::endl;
      }
    return out;
  }
  inline void operator()()
  {
    std::vector<T> t;

    for (int m = 2, m2 = 4; m2 < ux; ++m, m2 = m * m)
      {
	for (int n = m % 2 + 1; n < m; n += 2)
	  {
	    if (gcd(m, n) != 1)
	      continue;

	    int n2 = n * n;

	    int c = m2 + n2;

	    if (c > ux)
	      break;

	    int a = m2 - n2;
	    int b = 2 * m * n;

	    T tp(c, b, a, true); 
	    t.push_back(tp);
	    for (int k = 2, kx = ux / c; k <= kx; ++k)
	      t.push_back(tp * k);
	  }
      }
 
    std::map<int,V>::iterator vp = v.begin();
    V* vn = &vp->second;
 
    int np = 0;
    Q nq;

    std::sort(t.begin(), t.end());
    for (std::vector<T>::iterator i = t.begin(); i != t.end(); ++i)
      {
	while (i->c > vn->n)
	  {
	    (*vn)(np, nq.size());
	    vn = &(++vp)->second;
	  }

	if (i->prime)
	  ++np;

	nq += *i;
      }

    (*vn)(np, nq.size());
  }
};

int main()
{
  W w;

  while (std::cin.good())
    std::cin >> w;

  w();

  std::cout << w;

  return 0;
}

Written by Ciro Cavani

2012-04-25 at 1:00 pm

Publicado em C++, Puzzle

105 – The Skyline Problem

leave a comment »

105 – The Skyline Problem (pdf)

http://github.com/cirocavani/uva.onlinejudge.org-cxx/tree/master/105

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

struct N
{
  int l;
  int r;
  int h;
  N(int _l = 0, int _r = 0, int _h = 0) : l(_l), r(_r), h(_h) { }
};

class M
{

  int w;

  std::vector<N> n;

  std::vector<int> v;
    
public:

  M() : w(0) { }

  friend std::istream& operator>>(std::istream& in, M& m)
  {
    int l, h, r;
    in >> l >> h >> r >> std::ws;

    m.n.push_back(N(l, r, h));

    if (m.w < r)
      m.w = r;
  }

  friend std::ostream& operator<<(std::ostream& out, const M& m)
  {
    if (m.v.empty())
      return out;

    std::vector<int>::const_iterator i = m.v.begin();
    out << *i;
    while (++i != m.v.end())
      {
	out << " " << *i;
      }

    return out << std::endl;
  }

  M& operator()()
  {
    std::vector<int> h(w, 0);

    for (std::vector<N>::iterator i = n.begin(); i != n.end(); ++i)
      {
	std::binder2nd<std::less<int> > hidden(std::less<int>(), i->h);
        std::replace_if(&h[i->l], &h[i->r], hidden, i->h);
      }

    int _h = 0;
    for (int i = 0; i < h.size(); ++i)
      {
        if (_h != h[i])
	  {
	    v.push_back(i);
	    v.push_back(_h = h[i]);
	  }
      }
  
    v.push_back(w);
    v.push_back(0);

    return *this;
  }

};

int main()
{
  M m;

  while (std::cin.good())
    {
      std::cin >> m;
    }

  m();

  std::cout << m;

  return 0;
}

Written by Ciro Cavani

2012-04-19 at 6:20 pm

Publicado em C++, Puzzle

Bjarne Stroustrup – C++11 Style

with 2 comments

This presentation reflects my thoughts on what “Modern C++” should mean in the 2010s: a language for programming based on light-weight abstraction with direct and efficient mapping to hardware, suitable for infrastructure code.

Bjarne Stroustrup - C++11 Style

http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Keynote-Bjarne-Stroustrup-Cpp11-Style

Written by Ciro Cavani

2012-02-17 at 8:54 pm

Publicado em C++, Video

Bjarne Stroustrup, Andrew Sutton – A Concept Design for C++

leave a comment »

This talk presents the results of an effort to first focus on the design of concepts and their use; Only secondarily, we look at the design of language features to support the resulting concepts. We describe the problem, our approach to a solution, give examples of concepts for the STL algorithms and containers, and finally show an initial design of language features. We also show how we use a library implementation to test our design.

Bjarne Stroustrup, Andrew Sutton - A Concept Design for C++

http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/A-Concept-Design-for-C-

Written by Ciro Cavani

2012-02-17 at 4:26 am

Publicado em C++, Video

104 – Arbitrage

leave a comment »

104 – Arbitrage (pdf)

http://github.com/cirocavani/uva.onlinejudge.org-cxx/tree/master/104

#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>

class T
{

  const std::vector<float>& n;

  const T* t;

  int i;

  int s;

  float m;

  float _value;

public:

  T(const T& _t, int _i, float _r) : n(_t.n), t(&_t),
      i(_i), s(_t.s + 1), m(_t.m * _r), _value(m * n[i])
  { }
  T(int i0, const std::vector<float>& _n) : n(_n), t(0),
      i(i0), s(1), m(1.0)
  { }

  friend std::ostream& operator<<(std::ostream& out, const T& t)
  {
    std::list<int> u;

    for (const T* k = &t; k != 0; k = k->t)
      u.push_back(k->i + 1);

    for (std::list<int>::reverse_iterator i = u.rbegin(); i != u.rend(); ++i)
      out << *i << " ";
    
    return out << u.back();
  }

  int index() const { return i; }

  int size() const { return s; }

  float value() const { return _value; }

  bool loss() const { return _value == m && _value <= 1.0; }

};

class R
{

  std::vector<float> _vt;

  std::vector<float> _vr;

  std::vector<int> p;

public:

  R(int n) : _vt(n), _vr(n), p(n) { for (int i = 0; i < n; ++i) p[i] = i; }

  bool operator()(int i, int j) { return _vt[i] > _vt[j]; }

  float operator[](int i) const { return _vt[i]; }
 
  void vt(int i, float v) { _vt[i] = v; }
  void vr(int i, float v) { _vr[i] = v; }
  const std::vector<float>& vr() const { return _vr; }

  void sort() { std::sort(p.begin(), p.end(), *this); }
  std::vector<int>::iterator pbegin() { return p.begin(); }
  std::vector<int>::iterator pend() { return p.end(); }

};

class W
{

  int n;

  std::vector<R> u;

  T* t;

  T* search()
  {
    std::list<T*> m;

    for (int i = 0; i < n; ++i) m.push_back(new T(i, u[i].vr()));
 
    for (std::list<T*>::iterator mi = m.begin(); mi != m.end(); ++mi)
      {
	T* tn = *mi;
	
	if (tn->size() == n) break;

	R& r = u[tn->index()];

	for (std::vector<int>::iterator pi = r.pbegin(); pi != r.pend(); ++pi)
	  {
	    int i = *pi;

	    if (tn->index() == i) continue;

	    T* tx = new T(*tn, i, r[i]);
	    
	    if (tx->loss()) continue;
	    if (tx->value() > 1.01) return tx;

	    m.push_back(tx);
	  }
      }

    return 0;
  }
 
public:

  W() : t(0) { }

  friend std::istream& operator>>(std::istream& in, W& w)
  {
    in >> w.n >> std::ws;

    for (int i = 0; i < w.n; ++i) w.u.push_back(R(w.n));

    for (int i = 0; i < w.n; ++i)
      {
	R& r = w.u[i];

	for (int j = 0; j < w.n; ++j)
	  {
	    if (j == i)
	      {
		r.vt(i, 1.0);
		r.vr(i, 1.0);
		continue;
	      }

	    float _v;
	    in >> _v >> std::ws;
	    r.vt(j, _v);

	    R& _r = w.u[j];
	    _r.vr(i, _v);
	  }
      }

    std::for_each(w.u.begin(), w.u.end(), std::mem_fun_ref(&R::sort));

    return in;
  }

  friend std::ostream& operator<<(std::ostream& out, const W& w)
  {
    return w.t == 0 ? out << "no arbitrage sequence exists" : out << *w.t;
  }

  W& operator()()
  {
    t = search();
    return *this;
  }

};

void print(W& w)
{
  std::cout << w << std::endl;
}

int main()
{
  std::list<W> v;

  while (std::cin.good())
    {
      W w;
      std::cin >> w;
      v.push_back(w());
    }

  std::for_each(v.begin(), v.end(), print);

  return 0;
}

Written by Ciro Cavani

2011-03-24 at 5:35 am

Publicado em C++, Puzzle

103 – Stacking Boxes

leave a comment »

103 – Stacking Boxes (pdf)

http://github.com/cirocavani/uva.onlinejudge.org-cxx/tree/master/103

#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <algorithm>
#include <functional>

struct Q;
typedef std::vector<Q*> S;

struct SizeCmp : public std::binary_function<S, S, bool>
{

  bool operator() (const S& v1, const S& v2) const
  {
    return v1.size() < v2.size();
  }

};

struct Q
{

  int p;

  std::vector<int> v;

  Q(int i, int n) : p(i), v(n) {}

  friend std::istream& operator>>(std::istream& in, Q& q)
  {
    for (std::vector<int>::iterator i = q.v.begin(); i != q.v.end(); ++i)
      in >> *i >> std::ws;
    return in;
  }

  friend std::ostream& operator<<(std::ostream& out, const Q& q)
  {
    for (std::vector<int>::const_iterator i = q.v.begin(); i != q.v.end(); ++i)
      out << (i == q.v.begin() ? "" : " ") << *i;
    return out;
  }

  friend bool operator<(const Q& q1, const Q& q2)
  {
    return q1.v.front() < q2.v.front();
  }

  Q& sort()
  {
    std::sort(v.begin(), v.end(), rev_cmp);
    return *this;
  }

  static bool rev_cmp(int v1, int v2)
  {
    return v1 < v2;
  }

  bool fit(const Q& q)
  {
    for (size_t i = 0; i < v.size(); ++i)
      if (v[i] >= q.v[i])
	return false;

    return true;
  }

};

struct W
{

  int n;

  std::vector<Q> u;

  std::vector<int> v;

  friend std::istream& operator>>(std::istream& in, W& w)
  {
    int k;
    in >> k >> w.n >> std::ws;

    w.u = std::vector<Q>();

    for (int i = 0; i < k; ++i)
      {
	Q q = Q(i + 1, w.n);
	in >> q >> std::ws;
        w.u.push_back(q.sort());
      }

    return in;
  }

  friend std::ostream& operator<<(std::ostream& out, const W& w)
  {
    out << w.v.size() << std::endl;
    for (std::vector<int>::const_iterator i = w.v.begin(); i != w.v.end(); ++i)
      out << (i == w.v.begin() ? "" : " ") << *i;
    
    return out;
  }

  W& operator()()
  {
    std::sort(u.begin(), u.end());

    std::list<S> stacks;
    
    for (std::vector<Q>::iterator i = u.begin(); i != u.end(); ++i)
      {
	std::priority_queue<S, std::vector<S>, SizeCmp> max;

	for (std::list<S>::iterator s = stacks.begin(); s != stacks.end(); ++s)
	  if (s->back()->fit(*i))
	    {
	      S v = *s; // copy
	      v.push_back(&(*i));
	      max.push(v);
	    }

	if (!max.empty())
	  stacks.push_back(max.top());

	S stack;
	stack.push_back(&(*i));

	stacks.push_back(stack);
      }

    S& stack = *std::max_element(stacks.begin(), stacks.end(), SizeCmp());

    trace(stack);

    return *this;
  }
  
  void trace(const S& stack)
  {
    v.clear();
    for (S::const_iterator i = stack.begin(); i != stack.end(); i++)
      v.push_back((*i)->p);
  }

};

void evaluate(W& w)
{
  std::cout << w() << std::endl;
}

int main()
{
  std::vector<W> v;

  while (std::cin.good())
    {
      W w;
      std::cin >> w;
      v.push_back(w);
    }

  std::for_each(v.begin(), v.end(), evaluate);

  return 0;
}

Written by Ciro Cavani

2011-02-19 at 1:46 am

Publicado em C++, Puzzle