本文整理汇总了C++中vs::size方法的典型用法代码示例。如果您正苦于以下问题:C++ vs::size方法的具体用法?C++ vs::size怎么用?C++ vs::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vs
的用法示例。
在下文中一共展示了vs::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse_obstacles
vvb parse_obstacles(const vs &initial_map) {
vvb obstacles(initial_map.size()+2, vector<bool>(initial_map[0].size()+2, true));
for (int i = 0; i < initial_map.size(); i++) {
for (int j = 0; j < initial_map[i].size(); j++) {
obstacles[i+1][j+1] = (initial_map[i][j] == '*');
}
}
return obstacles;
}
示例2: print
void print(vs v){
int n=v.size();
for(int i=0;i<n; i++){
cout<<v[i]<<endl;
}
cout<<n;
}
示例3: solve
void solve(vs names,vs towns)
{
int n=names.size();
vs res(n);
map<string,int> f;
rep(i,n){
res[i]=shorten(names[i],towns[i]);
f[res[i]]++;
}
示例4: find_king
pii find_king(const vs &initial_map) {
for (int i = 0; i < initial_map.size(); i++) {
for (int j = 0; j < initial_map[i].size(); j++) {
if (initial_map[i][j] == 'X') {
return make_pair(i+1, j+1);
}
}
}
// never reaches
}
示例5: returnIndexOfVector
/*
* Returns an integer which is the index
* of a string in a vector of strings
*/
int returnIndexOfVector(vs &stringVector, string value)
{
int iii;
for (iii = 0; iii < stringVector.size(); iii++) {
if (stringVector[iii] == value) {
return iii;
}
}
return -1;
}
示例6: fill
string fill(vs ss)
{
int p=ss.size();
string res;
for(int i=0;i/p<ss[i%p].size();i++){
char c=ss[i%p][i/p];
res+=c=='.'?'0':c;
}
return res;
}
示例7: solve_naive
string solve_naive(vs ss)
{
int k=ss.size(),n=ss[0].size();
rep(i,k){
string s=ss[0]; sort(all(s));
string t=ss[i]; sort(all(t));
if(s!=t)
return "-1";
}
示例8: work
void work(map<vi, int> & ans, vs & s)
{
int n = s.size(), m = s[0].size();
rep(x, t[m])
{
vi key(n);
rep(i, n) rep(j, m)
key[i] += x / t[j] % 10 + '0' == s[i][j];
auto p = ans.find(key);
if(p == ans.end()) ans[key] = x;
else p->second = -1;
}
示例9: solve
int solve(int apos,int wpos,int k)
{
if(apos==a.size() && wpos==w.size()-1 && k) return 1;
if(apos==a.size() || wpos==w.size()) return 0;
int& res=dp[apos][wpos][k];
if(res!=-1) return res;
res=0;
for(int i=k;i<w[wpos].size();i++)
if(a[apos]==w[wpos][i]) res+=solve(apos+1,wpos,i+1);
if(k) res+=solve(apos,wpos+1,0);
return res;
}
示例10: printCase
void printCase(vs V, vvs A, vd f){
printf("Case Details:\n");
printf("--------------\n");
printf("Number Of Variables n: %d\n\n", V.size());
printf("Rules:\n");
printf("-------\n");
for(int i=0; i<A.size(); i++){
for(int j=0; j<A[i].size(); j++){
printf("%s ", A[i][j].c_str());
}
printf(":: %.3lf\n", f[i]);
}
}
示例11: makeMatch
string makeMatch(vs namesWomen, vs answersWomen, vs namesMen, vs answersMen, string queryWoman)
{
vp women;
vp men;
int size = namesWomen.size();
for(int i = 0; i<size; i++)
{
women.push_back(ps(namesWomen[i], answersWomen[i]));
men.push_back(ps(namesMen[i], answersMen[i]));
}
sort(women.begin(), women.end());
sort(men.begin(), men.end());
int compatible = 0;
vp dates;
for(vp::iterator it = women.begin(); it != women.end(); it++)
{
vp::iterator idealMale;
string wAnswer = it->second;
compatible = -1;
for(vp::iterator mit = men.begin(); mit != men.end(); mit++)
{
string mAnswer = mit->second;
int score = 0;
for(int x = 0; x < wAnswer.length(); x++)
{
if(wAnswer[x] == mAnswer[x])
score++;
}
if(score > compatible)
{
compatible = score;
idealMale = mit;
}
}
if(it->first == queryWoman)
return idealMale->first;
men.erase(idealMale);
}
string noMatch = "NO_MATCH";
return noMatch;
}
示例12: find_openspaces
void find_openspaces(const vs &initial_map, pii *spaces) {
int count = 0;
for (int i = 0; i < initial_map.size(); i++) {
for (int j = 0; j < initial_map[i].size(); j++) {
if (initial_map[i][j] == '.') {
spaces[count] = make_pair(i+1, j+1);
count++;
if (count == 2) {
return;
}
}
}
}
}
示例13: printPredictionsAndCalculateAccuracy
/*
* Outputs the predictions to file
* and returns the accuracy of the classification
*/
double printPredictionsAndCalculateAccuracy(vs &givenData, vs &predictions)
{
ofstream outputFile;
outputFile.open("decisionTreeOutput.txt");
int correct = 0;
outputFile << setw(3) << "#" << setw(16) << "Given Class" << setw(31) << right << "Predicted Class" << endl;
outputFile << "--------------------------------------------------" << endl;
for (int iii = 0; iii < givenData.size(); iii++) {
outputFile << setw(3) << iii + 1 << setw(16) << givenData[iii];
if (givenData[iii] == predictions[iii]) {
correct++;
outputFile << " ------------ ";
}
else {
outputFile << " xxxxxxxxxxxx ";
}
outputFile << predictions[iii] << endl;
}
outputFile << "--------------------------------------------------" << endl;
outputFile << "Total number of instances in test data = " << givenData.size() << endl;
outputFile << "Number of correctly predicted instances = " << correct << endl;
outputFile.close();
return (double)correct / 50 * 100;
}
示例14: classification
/*
* function: naive_bayes::classification 对数据进行分类
* return: 该数据最可能的目标属性值
*
*/
std::string naive_bayes::classification(vs& data)
{
assert((int)data.size() == num_attr - 1);
// 为了防止溢出,以下对概率值取了对数
int max_index = -1;
double p_max = -1e300; // 最大概率
vd p_targ_val; // 每个目标属性值对该数据的概率 P(data | target_attr[i])
p_targ_val.resize(num_targ, 0.0);
auto f = [&](double x, double u, double d)
{// 求正态分布概率密度
return std::exp(-(x - u) * (x - u) / (2 * d)) / sqrt(4 * std::acos(-1) * d);
};
for(int i = 0; i < num_targ; ++i)
{
auto& t = p_targ_val[i];
t = std::log(p_target[i]); // 取对数
for(int j = 0; j < num_attr - 1; ++j)
{
auto& p = p_datas[i][j];
if(is_numeric[j])
{
t += std::log(f(std::stod(data[j]), p.mean_value, p.variance));
}
else
{
auto it = attr_to_int[j].find(data[j]);
if(it == attr_to_int[j].end())
{
std::cerr<<"No such attribute value."<<std::endl;
exit(1);
}
t += std::log(p.p_attr[it->second]);
}
}
}
// 找到最大概率值
for(int i = 0; i < num_targ; ++i)
{
// std::cout<<p_targ_val[i]<<std::endl;
if(p_max < p_targ_val[i])
p_max = p_targ_val[i], max_index = i;
}
return int_to_attr[num_attr - 1][max_index];
}
示例15: shortestLadder
int shortestLadder(vector <string> level, int coinRow, int coinColumn){
M = level;
n = M.size();
m = M[0].size();
vi move(2);
move[0] = -1; move[1] = 1;
for(int l = 0; l < n; l++){
// cout<<"level = "<<l<<endl;
fi(n) fj(m) visited[i][j] = 0;
queue<pi> Q;
Q.push(mp(n-1, m-1));
visited[n-1][m-1] = 1;
while(!Q.empty()){
pi p = Q.front();
Q.pop();
int x = p.first, y = p.second;
// cout<<x<<" "<<y<<endl;
if(x+1 == coinRow && y+1 == coinColumn) return l;
//Move horizontally
for(int k : move){
if(valid(x, y+k)){
Q.push(mp(x, y+k));
visited[x][y+k] = 1;
}
}
//Move vertically
for(int i = 1; i <= l; i++){
for(int k : move){
if(valid(x+k*i, y)){
visited[x+k*i][y] = 1;
Q.push(mp(x+k*i, y));
}
}
}
}
}
}