1. 词频统计
题目描述
样例输入
代码
#include <bits/stdc++.h>using namespace std;int main()
{int n,m;cin>>n>>m;vector<int> ans1(m,0),ans2(m,0);while (n --) {int t;cin>>t;vector<int> vis(m+1,0);for (int i = 1;i <= t;i ++) {int x;cin>>x;vis[x] ++;}for (int i = 0;i < m;i ++) {if (vis[i+1]) {ans1[i] ++;}ans2[i] += vis[i+1];}}for (int i = 0;i < m;i ++) {cout<<ans1[i]<<" "<<ans2[i]<<endl;}
}
2. 相似度计算
题目描述
样例输入
代码
#include <bits/stdc++.h>using namespace std;int main()
{int n,m;cin>>n>>m;vector<string> s1(n),s2(m);string s;set<string> ans2;map<string,int> ans1;for (int i = 0;i < n;i ++) {cin>>s;for (int j = 0;j < s.size();j ++) {if (s[j] >= 'A'&&s[j] <= 'Z') {s[j] = s[j] - 'A' + 'a';}}s1[i] = s;ans2.insert(s);//cout<<s<<endl;if (ans1.find(s1[i])==ans1.end())ans1[s1[i]] = 1;// cout<<s1[i]<<endl;}int answer1 = 0;for (int i = 0;i < m;i ++) {cin>>s;for (int j = 0;j < s.size();j ++) {if (s[j] >= 'A'&& s[j] <= 'Z') {s[j] = s[j] - 'A' + 'a';}}s2[i] = s;//cout<<s<<endl;ans2.insert(s);if (ans1.find(s2[i])!=ans1.end()) {answer1++;//cout<<ans1.size()<<endl;ans1.erase(s2[i]);//cout<<ans1.size()<<endl;}}cout<<answer1<<endl<<ans2.size()<<endl;
}
3. 化学方程式配平
题目描述
样例输入
代码
#include <bits/stdc++.h>using namespace std;
double a[105][105];
const double eps = 1e-8;
int huajian2(int n,int m)//亦或矩阵的化简
{int row = 1;for (int i = 1;i <= m;i ++) {bool flag = 0;for (int j = row;j <= n;j ++) {if (fabs(a[j][i]) > eps) flag = 1;} if (!flag) continue;if (fabs(a[row][i])<eps) {for (int j = row + 1;j <= n;j ++) {if (a[j][i]) {for (int k = i;k <= m;k ++) swap(a[row][k],a[j][k]);break;}}}for (int j = row+1;j <= n;j ++) {for (int k = i+1;k <= m;k ++) {a[j][k] -= a[row][k]*(a[j][i]/a[row][i]);}a[j][i] = 0;} row ++;}int cnt = 0;for (int i = 1;i <= n;i ++) {bool flag = 0;for (int j = 1;j <= m; j++ )if (fabs(a[i][j])>eps) flag = 1;if (flag) cnt ++;}return cnt;
}
double to_int(string s)
{double x = 0;for (int i = 0;i < s.size();i ++) {x=x*10+s[i]-'0';}return x*1.0;
}
void solve()
{int t;cin>>t;int c_cnt = 0; map<string,int> s_sum;for (int i = 1;i <=100;i ++ ) {for (int j = 1;j <= 100;j ++) a[i][j] = 0*1.0;}for (int i = 1;i <= t;i ++) {string s;cin>>s;string t_s = "",int_s = "";vector<double> i1;vector<string> s1;for (int j = 0;j < s.size();j ++){if (s[j] >= 'a' && s[j] <= 'z') {t_s += s[j];} else {if (t_s!="")s1.push_back(t_s);if (s_sum.find(t_s) == s_sum.end()) s_sum[t_s] = ++ c_cnt;t_s = "";} }int_s = "";for (int j = 0;j < s.size();j ++) {if (isdigit(s[j])) {int_s += s[j];} else {if (int_s!="")i1.push_back(to_int(int_s));int_s = "";}}i1.push_back(to_int(int_s));int_s = "";for (int j = 0;j < s1.size();j ++) {a[s_sum[s1[j]]][i] = i1[j];}}int ans = huajian2(c_cnt,t);if (ans < t) cout<<"Y"<<endl;else cout<<"N"<<endl;
}int main()
{// if (eps>0)// cout<<eps<<endl;int n;cin>>n;while (n --) {solve();}
}
4. 十滴水
题目描述
输入格式及样例输入
代码
#include <bits/stdc++.h>using namespace std;int main()
{int c,m,n;cin>>c>>m>>n;map<int,int> water;set<int> w_arr;for (int i = 1;i <= m;i ++) {int x,w;cin>>x>>w;w_arr.insert(x);water[x] = w;}set<int> five_s;while (n --) {int p;cin>>p;water[p] ++;if (water[p] >= 5) {five_s.insert(p);}// for (auto x:five_s) {// cout<<x<<" : ";// }cout<<endl;// for (auto x:w_arr) {// cout<<x<<" :: ";// }cout<<endl;while (int(five_s.size())!=0) {int xx = *(five_s).begin();set<int>::iterator iter = w_arr.find(xx);if(w_arr.size() == 1) {w_arr.erase(xx);break;}iter++;if ( iter != w_arr.end()) {// iter++;int xx = *(iter);water[xx] ++;if (water[xx] >= 5) {five_s.insert(xx);// vis[xx] = 1;} }iter = w_arr.find(xx);if (iter != w_arr.begin()){iter--;int xx = *iter;water[xx] ++;// cout<<xx<<":"<<i<<endl;if (water[xx] >= 5) {five_s.insert(xx);// vis[xx] = 1;} }five_s.erase(five_s.find(xx));w_arr.erase(w_arr.find(xx));water.erase(water.find(xx));}// for (auto x:w_arr) {// cout<<x<<" : "<<water[x]<<"!!!";// }cout<<endl;cout<<w_arr.size()<<endl;}
}