mapStudent[456] = "student_second"; 遍历!! 之前从hcy学长那里学到了直接用迭代器来遍历,其实也就等于一个for循环,但是map不能轻易用for循环来遍历 比如(for(int i=0;i<map.size();i++)),这里就相当于我们自动默认了map的key为int,当然不对! 于是我们使用迭代器来遍历map map<x,y> some::iterator ...
**思路:**用一个map记录每个字符串的次数,遍历一遍即可~ 代码: #include<bits/stdc++.h>usingnamespacestd;constintmaxn=1e6+7; map<string,int>mp; string s[maxn]; std::map<string,int>::iterator it;boolcmp(string a,string b){returna<b; }intmain(){intn;cin>>n;for(inti=1;i<=n;i...
map<string,int> >mp;map<string,int>cnt;std::map<string,int>::iterator it;int main(){int n,m;string a,b;scanf("%d%d",&n,&m);while(m--){cin>>a>>b;if(!mp[a][b]){mp[a][b]=mp[b][a]=1;cnt[a]++;cnt[b]++;}}int maxx=-1;it=cnt.begin();while(it!=cnt.end())...
void sol(){ map<string,int> mp; string s="ABCDEABCDE"; rep(i,0,s.size()-2) { mp[s.substr(i,2)]=1; } reverse(all(s)); rep(i,0,s.size()-2) { mp[s.substr(i,2)]=1; } string a,b;cin>>a>>b; cout<<(mp.count(a)==mp.count(b)?"Yes":"No"); } ...
C - Swappable 在数组中找到满足条件的数对\((i,j)\) \(1 \le i < j \le N (N\in[2,3e5])\) \(A_i \not= A_j\) 一道经典利用map减少搜索规模的题, 先假设每个数互不相同:ans = n * (n - 1) / 2 map存每个数出现的次数,然后减去相同的情况ans -= x * (x - 1) / 2 ...
定义dp[i] [j]状态为以s[i]为pn s[j]为qn的方案数容易得到状态转移方程f[next[i+1] [c]] [next[j+1] [c]]=f[next[i+1] [c]] [next[j+1] [c]]+f[i] [j]. 首先枚举pn的位置,然后把p1 q1初始化(即在范围内 p1<=i &&q1<=n)就可以 ...
Try to map the sum of the index of first element and height of the first element with: The difference in the index of the second element and its height. Store the sum of the index and height of first element in the map in one pass. In the second pass count how many occurrences ...
C代码 #include<bits/stdc++.h>usingnamespacestd; inta[25],n; intmain{scanf("%d",&n);for(inti =1;i <= n;++i)scanf("%d",a+i);intans =2e9+5;for(intS =0;S < (1<<n);++S){intsmA =0, smB =0;for(inti =0;i < n;++i){if((S>>i)&1){smB += a[i+1];}else{...
inta[maxn], n;ll sum[maxn], f[maxn], k, g_all =0;constll p =998244353;map<ll, ll> g;llpower(ll a, ll b){ll ret =1;while(b) {if(b &1)ret = ret * a % p;a = a * a % p;b >>=1;}returnret;}intmain{ios::sync_with_stdio(false);cin>> n >> k;for(inti...
#include<bits/stdc++.h>using namespace std;#define endl'\n';voidbest_coder(){int n;cin>>n;unordered_map<string,string>g(n);unordered_map<string,pair<int,int>>vp(n);for(int i=0;i<n;++i){string a,b;cin>>a>>b;g[b]=a;++vp[a].first;++vp[b].second;}queue<string>q;for...