↓ Skip to main content
  1. Tags/

Vector

2017

cpp vector学习笔记

·785 words·2 mins
起因是百度实习二面的时候被问了一道类似这样的题: 给我下面的代码,问有没有什么问题。 1/* *********************************************** 2Author :111qqz 3Created Time :2017年02月28日 星期二 14时49分37秒 4File Name :vector.cpp 5************************************************ */ 6#include <cstdio> 7#include <vector> 8#include <ctime> 9using namespace std; 10int func( int x ) //此处函数的条件是不单调...这样才可以触发问题. 11{ 12 return (x-50)*(x-50)+1; 13} 14int main() 15{ 16 17 vector<int>vec; 18 int *pint = NULL; 19 for ( int i = 0 ; i < 100 ; i++) 20 { 21 int x = func(i); 22 vec.push_back(x); 23 if (x<500) 24 { 25 pint = & vec[0]; 26 } 27 } 28 if (pint) 29 *pint = 0 ; 30 int siz = vec.size(); 31 for ( int i = 0 ; i < siz ; i++) printf("%d\n",vec[i]); 32 return 0; 33} 面试的时候只给了部分代码,func函数没有给出。

2015

codeforces 29 C. Mail Stamps

·403 words·1 min
http://codeforces.com/contest/29/problem/C 题意:给出n个边的关系,保证可以构成一条链。正向或者反向输出这个链。 思路:由于下标很大(1E9),而关系个数只有1E5..需要离散化。。而且离散化的同时不能丢失边的关系。。。实际上。。直接用vector+map就好了。。。 map >e;即可。然后找到一个度为1的点。。做个dfs…