本文整理汇总了C++中map::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ map::clear方法的具体用法?C++ map::clear怎么用?C++ map::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map
的用法示例。
在下文中一共展示了map::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isMatch
bool isMatch(string s, string p) {
m.clear();
int ans = isMatch(s,p,0,0);
return ans;
}
示例2: getExpectedTime
double getExpectedTime(int listSize, int S, int a, int b)
{
f.clear();
return getF(listSize, S, a, b);
}
示例3: renderScene
//.........这里部分代码省略.........
//glVertex3f(fit.getPosition(0)[0],fit.getPosition(0)[1],fit.getPosition(0)[2]);
//glVertex3f(fit.getPosition(2)[0],fit.getPosition(2)[1],fit.getPosition(2)[2]);
_LINES.push_back(fit.getPosition(0));
_LINES.push_back(fit.getPosition(2));
//createControlPoints(_LINES.size()-2,fit.getPosition(0),fit.getPosition(2));
}
h++;
}
// c-b
if(c == a2 || c == b2 || c == c2)
if(b == a2 || b == b2 || b == c2){
if(fit.getNormal(0).dot(nit.getNormal(0)) < thresh){
count_lines_drawn++;
//glVertex3f(fit.getPosition(1)[0],fit.getPosition(1)[1],fit.getPosition(1)[2]);
//glVertex3f(fit.getPosition(2)[0],fit.getPosition(2)[1],fit.getPosition(2)[2]);
_LINES.push_back(fit.getPosition(1));
_LINES.push_back(fit.getPosition(2));
//createControlPoints(_LINES.size()-2,fit.getPosition(1),fit.getPosition(2));
}
h++;
}
}
glEnd();
}
//glutSwapBuffers();
// DRAW _CONTROLPOINTS_
//sorted lines by length in _LINES
//sortLines();
// create CP's now
_HITPOINTS.clear();
_CONTROLPOINTS.clear();
_CP2D.clear();
_LINES2D.clear();
/*for(int i(0);i < _LINES.size()/10;i=i+2){
createControlPoints(i,_LINES[i],_LINES[i+1]);
}*/
/*
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_POINTS);
glColor3f(0,1,0);
// for each line
for(int i(0);i < _CONTROLPOINTS.size(); ++i){
// get CP-vector
vector<Pnt3f> cps = _CONTROLPOINTS[i];
// for every single controlpoint
for(int j(0);j<cps.size();++j)
glVertex3f(cps[i][0],cps[i][1],cps[i][2]);
}
glEnd();
glutSwapBuffers();
*/
cout << "Lines over Threshold :: "<< _CONTROLPOINTS.size() <<endl;
cout << "Shared Edges :: " << h <<endl;
cout << "Lines drawn :: " << count_lines_drawn << endl;
cout << "Lines :: "<< _LINES.size()<<endl;
//open cv
stringstream stream;
stream << "pics/undist/resize/";
stream << q;
stream << ".bmp";
示例4: track
bool track( std::map< unsigned long long, std::map<int,cv::Point2d> >* p_result, std::map<unsigned long long, std::multimap<int,cv::Point2d> >* p_ext_result, const Mat& occupancy, unsigned long long time_stamp )
{
static TIME_MICRO_SEC timeTracking; // [email protected];~9o(B[usec]
// [timeTracking - commonParam.termTracking, timeTrackig) [email protected]=hM}$r9T$&;v$r0UL#$9$k(B
static SamplerPosXYTVID sampler; // $BFCD'NL%5%s%W%i(B
// storageLUM
// 時刻tk(キー)に対応するLUM集合へのマップ
// 時刻tkに対応する等速直線運動集合とは、[tk - extractlumParam.term, tk)のPEPMapから作成した等速直線運動集合のことである。
static LUMStorage storageLUM;
// tableLUMSlice
// LUMスライステーブル
// 時刻tk(キー)におけるLUMスライスの配列へのマップ
static LUMSliceTable tableLUMSlice;
// storageTrajectory
// 作成中の軌跡要素
static vector<TrajectoryElement> storageTrajectoryElement;
// resultTrajectory
// 追跡結果(IDと軌跡のマップ)
static map<int,CTrajectory> resultTrajectory;
//static vector<CTrajectory> prevTrajectoriesClustered;
static map<unsigned long long, std::multimap<int,cv::Point2d> > remainedExtendedResult;
// idNext
// 追跡結果(IDと軌跡のマップ)
static int idNext;
static TIME_MICRO_SEC timeEarliestPEPMap;
static bool flgTrackingStarts;
static set<TIME_MICRO_SEC> time_of_received_pepmap;
bool ret = false;
if( flgFirst ) {
sampler.clear();
storageLUM.clear();
tableLUMSlice.clear();
storageTrajectoryElement.clear();
resultTrajectory.clear();
remainedExtendedResult.clear();
idNext = 1;
timeEarliestPEPMap = time_stamp;
timeTracking = timeEarliestPEPMap + commonParam.termTracking;
//timeTracking = commonParam.termTracking + 1000000000; // debug code
flgFirst = false;
flgTrackingStarts = true;
logTracking.init( "tracking.log" );
viewer.SetStartTime( timeEarliestPEPMap );
}
// debug code
//time_stamp = time_stamp - timeEarliestPEPMap + 1000000000;
if( flgTrackingStarts ) {
logTracking.set_tracking_block( timeTracking - commonParam.termTracking, timeTracking );
logTracking.start();
viewer.SetTrackingStatus( 0 );
viewer.SetTrackingBlock( timeTracking - commonParam.termTracking, timeTracking );
flgTrackingStarts = false;
}
time_of_received_pepmap.insert( time_stamp );
logTracking.making_trajectory( TrackingProcessLogger::Start );
// PEPMapをサンプラに追加する
AddPEPMapToSampler( occupancy
, time_stamp
, &sampler
, extractlumParam.minPEPMapValue
, extractlumParam.maxPEPMapValue );
//
// LUM抽出
vector<TIME_MICRO_SEC> addedTime;
for( TIME_MICRO_SEC tk = timeTracking - commonParam.termTracking; tk <= time_stamp; tk += extractlumParam.interval ) {
if( storageLUM.find( tk ) == storageLUM.end() ) {
// 時刻tkのLUMを抽出
ExtractLUM( &sampler
, tk
, &storageLUM[ tk ]
, &commonParam
, &extractlumParam
, true );
addedTime.push_back( tk );
}
}
//
// LUMスライステーブル作成
if( !storageLUM.empty() ) {
TIME_MICRO_SEC timeLatestLUM = storageLUM.rbegin()->first;
//.........这里部分代码省略.........
示例5: main
int main() {
int test_case;
int first = 1;
scanf("%d", &test_case);
while (test_case--) {
if (!first) {
printf("\n");
}
memset(head, -1, sizeof(head));
memset(value, 0, sizeof(value));
maps.clear();
edge_number = 0;
cnt = 1;
source = 0;
plug.clear();
int plug_number, device, adapter;
scanf("%d", &plug_number);
int temp = plug_number;
for (int i = 1; i <= plug_number; i++) {
string name;
cin >> name;
plug.push_back(cnt);
if (maps[name]) {
value[maps[name]]++;
temp--;
}
else {
value[cnt] = 1;
maps[name] = cnt++;
}
}
scanf("%d", &device);
for (int i = 1; i <= device; i++) {
string device_name, plug;
cin >> device_name >> plug;
int id_1 = maps[plug];
int id_2 = cnt;
maps[device_name] = cnt++;
addEdge(source, id_2, 1, 0);
addEdge(id_2, id_1, 1, 0);
}
scanf("%d", &adapter);
for (int i = 1; i <= adapter; i++) {
string name_1, name_2;
cin >> name_1 >> name_2;
if (!maps[name_1]) {
plug.push_back(cnt);
maps[name_1] = cnt++;
}
if (!maps[name_2]) {
plug.push_back(cnt);
maps[name_2] = cnt++;
}
int id_1 = maps[name_1];
int id_2 = maps[name_2];
addEdge(id_1, id_2, INF, 0);
}
destination = cnt++;
for (int i = 0; i < plug.size(); i++) {
addEdge(plug[i], destination, value[plug[i]], 0);
}
int ans;
ans = dinic();
printf("%d\n", device - ans);
first = 0;
}
return 0;
}
示例6: main
int main()
{
int n,m,nm,r,s,tmp,q,i,j;
char _string_tmp[40];
int cas,ans;
scanf("%d",&cas);
memset(a,0,sizeof(a));
for(i=2; i<=10000; i++)
{
if(a[i]==0)
{
isprime[i]=1;
for(j=i+i; j<=10000; j+=i)
a[j]=1;
}
}
while(cas--)
{
memset(pro_first,false,sizeof(pro_first));
memset(pro_second,false,sizeof(pro_second));
scanf("%d%d",&n,&m);
scanf("%d",&r);
while(r--)
{
scanf("%d",&tmp);
pro_first[tmp] = true;
}
scanf("%d",&s);
while(s--)
{
scanf("%d",&tmp);
pro_second[tmp] = true;
}
Map.clear();
scanf("%d",&q);
while(q--)
{
scanf("%s%d",_string_tmp,&tmp);
Map[_string_tmp] = tmp;
}
for(i=0; i<n; i++)
{
info[i].score=0;
scanf("%s%s%s",info[i].name,info[i].team,info[i].sex);
for(j=0;info[i].name[j];j++){
if(info[i].name[j] >='A' && info[i].name[j]<='Z'){
info[i]._name[j] = info[i].name[j] - 'A' + 'a';
}else{
info[i]._name[j] = info[i].name[j];
}
}
if(info[i].sex[0]=='F')info[i].score+=33;
tmp =Map[info[i].team] ;
info[i].score+=getscore(tmp);
scanf("%d",&info[i].pro_num);
scanf("%d",&info[i].contest_num);
//cout<< info[i].score <<" #$#### "<<endl;
while(info[i].pro_num--)
{
scanf("%d",&tmp);
double scores=0;
bool ok = false;
if(pro_first[tmp])
{
info[i].score+=2.5,scores = 2.5;
ok = true;
}
else if(pro_second[tmp])
{
info[i].score+=1.5,scores = 1.5;
ok = true;
}
else if(isprime[tmp])
{
info[i].score+=1.0,scores = 1.0;
ok = true;
}
else if(!ok){
info[i].score+=0.3,scores = 0.3;
}
}
for(j=0; j<info[i].contest_num; j++)
{
scanf("%lf",&info[i].contest_str[j]);
}
// cout<<i<< " $$$$$$$$$$$ "<<info[i].score<<endl;
if(info[i].contest_num>=3)
{
sort(info[i].contest_str,info[i].contest_str+info[i].contest_num);
double dtmp = info[i].contest_str[info[i].contest_num-3];
//.........这里部分代码省略.........
示例7: distanceToDestination
int distanceToDestination(vector <string> signs, string destination)
{
N=signs.size();
for(int i=0;i<N;i++)
for(int j=0;j<(int)signs[i].size();j++)
if (signs[i][j]==';')
signs[i][j]=' ';
hash.clear();
tot=0;
int T=getnum(destination);
vector<pair<int,int> > v[MAXN];
for(int i=0;i<N;i++)
{
stringstream in(signs[i]);
string str;
int x;
while(in>>str>>x)
{
int a=getnum(str);
v[i].pb(mp(a,x));
}
sort(v[i].begin(),v[i].end());
}
memset(dis,-1,sizeof(dis));
mem=pool;
for(int i=0;i<N;i++)
for(int j=i+1;j<N;j++)
{
for(int a=0,b=0;a<(int)v[i].size();a++)
{
while(b<(int)v[j].size() && v[j][b].first<v[i][a].first)
b++;
if (b<(int)v[j].size())
{
if (v[i][a].first==v[j][b].first)
{
int nd=v[i][a].second-v[j][b].second;
if (nd<=0)
return -1;
if (dis[i][j]==nd)
continue;
if (dis[i][j]==-1)
{
dis[i][j]=nd;
addedge(j,i,nd*MAXN);
addedge(i,j,-nd*MAXN);
}
else
return -1;
}
}
else
break;
}
}
if (!spfa())
return -1;
int ans=-1;
for(int i=0;i<N;i++)
if (i==N-1 || dis[i][N-1]!=-1)
for(int j=0;j<(int)v[i].size();j++)
if (v[i][j].first==T)
{
ans=v[i][j].second;
if (i!=N-1)
ans-=dis[i][N-1];
break;
}
if (ans<0)
return -1;
for(int i=0;i+1<N;i++)
addedge(i,i+1,-1);
for(int i=0;i<N;i++)
addedge(N,i,0);
for(int i=0;i<N;i++)
dist[i]=oo;
dist[N]=0;
bool flag=true;
for(int i=0;i<N+1 && flag;i++)
{
flag=false;
for(Node *p=pool;p<mem;p++)
if (dist[p->u]!=oo && dist[p->v]>dist[p->u]+p->w)
{
dist[p->v]=dist[p->u]+p->w;
flag=true;
}
}
if (flag)
return -1;
return ans;
}
示例8: minReversal
int minReversal(string init, string goal) {
memo.clear();
int ret = solve(init, goal);
if (ret >= 10000) return -1;
return ret;
}
示例9: solve
inline void solve() {
n = getnum();
q = getnum();
cnt.clear();
for (int i = 1; i <= n; i++) {
hus[i].clear();
wife[i].clear();
hus[i].push_back(i);
wife[i].push_back(i);
hus_idx[i] = i;
wife_idx[i] = i;
cnt[make_pair(i, i)] = 1;
}
int ans = 0, cur_ans = 0;
for (int t = 1; t <= q; t++) {
int type = getnum();
int x = getnum();
int y = getnum();
if (type == 1) {
int fx = hus_idx[x];
int fy = hus_idx[y];
if (fx != fy) {
if (hus[fx].size() > hus[fy].size())
swap(fx, fy), swap(x, y);
vector<int> &_ = hus[fx];
vector<int> &__ = hus[fy];
for (int i = 0; i < (int)_.size(); i++) {
int now = _[i];
info cur = make_pair(fx, wife_idx[now]);
info nxt = make_pair(fy, wife_idx[now]);
if (cnt.count(cur)) {
int cur_value = cnt[cur];
if (cnt.count(nxt)) {
int nxt_value = cnt[nxt];
update(cur_ans, (ll)cur_value * nxt_value % mod);
cnt[nxt] += cur_value;
} else {
cnt[nxt] = cur_value;
}
cnt.erase(cur);
}
__.push_back(now);
hus_idx[now] = fy;
}
_.clear();
}
} else {
int fx = wife_idx[x];
int fy = wife_idx[y];
if (fx != fy) {
if (wife[fx].size() > wife[fy].size())
swap(fx, fy), swap(x, y);
vector<int> &_ = wife[fx];
vector<int> &__ = wife[fy];
for (int i = 0; i < (int)_.size(); i++) {
int now = _[i];
info cur = make_pair(hus_idx[now], fx);
info nxt = make_pair(hus_idx[now], fy);
if (cnt.count(cur)) {
int cur_value = cnt[cur];
if (cnt.count(nxt)) {
int nxt_value = cnt[nxt];
update(cur_ans, (ll)cur_value * nxt_value % mod);
cnt[nxt] += cur_value;
} else {
cnt[nxt] = cur_value;
}
cnt.erase(cur);
}
wife_idx[now] = fy;
__.push_back(now);
}
_.clear();
}
}
update(ans, (ll)t * cur_ans % mod);
}
printf("%d\n", ans);
}
示例10: init
void init(){
nodes.clear();
valid = true;
nNodes = 0;
}
示例11: BFS
int BFS(string s)
{
// debug(s)
visited.clear();
visited[s]=1;
dist[s]=0;
queue <string> q;
q.push(s);
while(!q.empty())
{
string u = q.front(); q.pop();
// debug(u)
if(u==dest) return dist[u];
///1st ta k change
string v = u;
v[0]=MOD((int)(v[0]-'a')-1)+'a';
if(!forbidden[v] && visited[v]==0)
{
visited[v]=1;
dist[v] = dist[u]+1;
q.push(v);
}
v = u;
v[0]=MOD((int)(v[0]-'a')+1)+'a';
if(!forbidden[v] && visited[v]==0)
{
visited[v]=1;
dist[v] = dist[u]+1;
q.push(v);
}
v = u;
v[1]=MOD((int)(v[1]-'a')-1)+'a';
if(!forbidden[v] && visited[v]==0)
{
visited[v]=1;
dist[v] = dist[u]+1;
q.push(v);
}
v = u;
v[1]=MOD((int)(v[1]-'a')+1)+'a';
if(!forbidden[v] && visited[v]==0)
{
visited[v]=1;
dist[v] = dist[u]+1;
q.push(v);
}
v = u;
v[2]=MOD((int)(v[2]-'a')-1)+'a';
if(!forbidden[v] && visited[v]==0)
{
visited[v]=1;
dist[v] = dist[u]+1;
q.push(v);
}
v = u;
v[2]=MOD((int)(v[2]-'a')+1)+'a';
if(!forbidden[v] && visited[v]==0)
{
visited[v]=1;
dist[v] = dist[u]+1;
q.push(v);
}
}
return -1;
}
示例12: clear
void clear() {
m_map.clear();
}
示例13: main
int main()
{
freopen("t.in", "r", stdin);
#ifdef _MSC_VER
freopen("input.txt","r",stdin);
uint64 time_used1=0,time_used2=0;
#endif
memset(C,0,sizeof(C));
for (int i=0;i<32;i++) for (int j=0;j<=i;j++) C[i][j]=(j==0)?1:(C[i-1][j-1]+C[i-1][j]);
int n,m;
double x;
int testcase;
preprocess();
double start_time=(double)clock();
scanf("%d",&testcase);
for (int case_id=0;case_id<testcase;case_id++)
{
scanf("%d%d%lf",&m,&n,&x);
if (fabs(x)<1e-6)
{
printf("%6e\n",0.0);
continue;
}
if (n>10000000)
{
double y=fmod(x*n,pi+pi);
int d=(int)(y/(pi+pi)*M+0.5);
if (d<0) d=0;
if (d>M-1) d=M-1;
double ret=get_c(n-1,m-1)*f[m][d];
printf("%6e\n",ret);
continue;
}
#ifdef _MSC_VER
uint64 time1=rdtsc();
#endif
prepare(n,m,x);
#ifdef _MSC_VER
uint64 time2=rdtsc();
time_used1+=time2-time1;
#endif
memset(visited,false,sizeof(visited));
double *ret=solve(n,n,m,0,x);
#ifdef _MSC_VER
uint64 time3=rdtsc();
time_used2+=time3-time2;
#endif
#ifdef _MSC_VER
printf("%6e\n",ret[m]);
double r1=ret[m];
M2.clear();
double r2=(n>=1000)?r1:solve2(n,m,x);
if (fabs(r1-r2)>max(1.0,fabs(r2))*1e-5)
{
printf("ERROR %d %d %.2lf\n%.6lf\n%.6lf\n",n,m,x,r1,r2);
return 0;
}
printf("PASSED...\n");
#else
printf("%6e\n",ret[m]);
double current_time=(double)clock();
if (current_time-start_time>(double)CLOCKS_PER_SEC && case_id+1>=5)
break;
#endif
}
#ifdef _MSC_VER
printf("DONE!\n");
printf("T1 = %.3lf\n",(double)time_used1/1e9);
printf("T2 = %.3lf\n",(double)time_used2/1e9);
#endif
return 0;
}
示例14: next
// return 1 for success, 0 at end of data
// Access (all of) the data for the next epoch. As long as this function
// returns zero, there is more data to be accessed. Ignore passes with
// Status less than zero.
// @param indexMap map<unsigned int, unsigned int> defined so that all the
// data in the current iteration is found at
// SatPassList[i].data(j) where indexMap[i] = j.
// @throw if time tags are out of order.
int SatPassIterator::next(map<unsigned int, unsigned int>& indexMap) throw(Exception)
{
int i,j,numsvs;
size_t k;
GSatID sat;
numsvs = 0;
indexMap.clear();
nextIndexMap.clear();
while(numsvs == 0) {
if(listIndex.size() == 0) return 0;
// loop over active SatPass's
map<GSatID,int>::iterator kt = listIndex.begin();
kt = listIndex.begin();
while(kt != listIndex.end()) {
sat = kt->first;
i = kt->second;
j = dataIndex[sat];
if(SPList[i].Status < 0) continue; // should never happen
if(countOffset[sat] + SPList[i].spdvector[j].ndt == currentN) {
// found active sat at this count - add to map
nextIndexMap[i] = j;
numsvs++;
// increment data index
j++;
if(j == SPList[i].spdvector.size()) { // this pass is done
indexStatus[i] = 1;
// find the next pass for this sat
for(k=i+1; k<SPList.size(); k++) {
if(SPList[k].Status < 0) // bad pass
continue;
if(SPList[k].sat != sat) // wrong sat
continue;
if(indexStatus[k] > 0) // already done
continue;
// take this one
indexStatus[k] = 0;
i = listIndex[sat] = k;
dataIndex[sat] = 0;
countOffset[sat]
= int((SPList[i].firstTime - FirstTime)/DT + 0.5);
break;
}
}
else {
dataIndex[sat] = j;
}
} // end if found active sat at this count
// increment the iterator
if(indexStatus[i] > 0) { // a new one was not found
listIndex.erase(kt++); // erasing a map - do exactly this and no more
}
else kt++;
} // end while loop over active SatPass's
currentN++;
} // end while robs.numSvs==0
indexMap = nextIndexMap;
return 1;
}
示例15: main
int main()
{
int T;
cin >> T;
for (int ti = 0; ti < T; ++ti) {
int n;
cin >> n;
mp.clear();
for (int i = 1; i <= n; ++i)
g[i].clear();
for (int i = 1; i <= n; ++i) {
string name;
cin >> name;
city[i] = name;
mp[name] = i;
int p;
cin >> p;
for (int j = 0; j < p; ++j) {
int nr, cost;
cin >> nr >> cost;
g[i].push_back(make_pair(cost, nr));
}
}
map<pair<int, int>, int> cache;
int r;
cin >> r;
for (int i = 0; i < r; ++i) {
string name1, name2;
cin >> name1 >> name2;
int idx1 = mp[name1], idx2 = mp[name2];
if (idx1 == idx2) { cout << 0 << endl; continue; }
if (idx1 > idx2) swap(idx1, idx2);
if (((cache).find(make_pair(idx1, idx2)) != (cache).end())) {
cout << cache[make_pair(idx1, idx2)] << endl;
continue;
}
// for (int j = 1; j <= n; ++j)
// dist[j] = -1;
map<int, long long> dist;
dist[idx1] = 0;
set<pair<long long, int> > st;
for (int j = 0; j < (int)(g[idx1]).size(); ++j)
st.insert(g[idx1][j]);
while (!st.empty()) {
pair<int, int> head = *st.begin();
st.erase(st.begin());
int node = head.second, cost = head.first;
dist[node] = cost;
cache[make_pair(min(idx1, node), max(idx1, node))] = cost;
if (node == idx2) break;
for (int j = 0; j < (int)(g[node]).size(); ++j) {
int node2 = g[node][j].second, cost2 = g[node][j].first;
if (((dist).find(node2) != (dist).end()) &&
dist[node] + cost2 < dist[node2])
st.erase(make_pair(dist[node2], node2));
st.insert(make_pair(dist[node] + cost2, node2));
dist[node2] = dist[node] + cost2;
}
}
cout << dist[idx2] << endl;
}
}
}