//第一题 #include<bits/stdc++.h> using namespace std; bool is(string temp) { stack<int> d; for(int i=0;i<temp.size();i++) { if(temp[i]=='(') d.push(i); else { if(d.empty()) { return false; } else d.pop(); } } if(!d.empty()) return false; return true; } int main() { vector<int> ans; int n;cin>>n; string temp; cin>>temp; int k=0; for(int i=0;i<temp.size();i++) { string x =temp; x.erase(x.begin()+i); if(is(x)) {ans.push_back(i);k++;} } cout<<k<<endl; for(auto& c :ans) cout<<c+1<<" "; return 0; } //第二题 #include<bits/stdc++.h> using namespace std; int main() { double d; cin>>d; for(int y=1;y<=30;y++) { for(int x=0;x<=y;x++) { double temp = (double)x/y*100; double value = (double) round(temp*100)/100; if(value==d) {cout<<x<<"/"<<y<<endl;return 0;} } } return 0; } //第三题 #include<bits/stdc++.h> using namespace std; int gcd(int a ,int b) { return !b?a:gcd(b,a%b); } int main() { int T; cin>>T; vector<string> ans; while(T--) { int n,m; cin>>n>>m; vector<vector<int>> d(m,vector<int>(2)); for(int i=0;i<m;i++) { cin>>d[i][0]; } for(int i=0;i<m;i++) { cin>>d[i][1]; } int all=0,yes=0; do{ int prel=d[0][0],prer=d[0][1]; all++; bool flag=true; for(int i=1;i<m;i++) { if(prel>d[i][1]||prer<d[i][0]) { flag=false; break; } else { prel = d[i][0];prer = d[i][1]; } } if(flag) yes++; } while (next_permutation(d.begin(),d.end())); if(yes==0) ans.push_back("impossible "); else { int g = gcd(yes,all); ans.push_back(to_string(yes/g)+"/"+to_string(all/g)+" "); } } for(auto&c:ans) cout<<c; return 0; }
全部评论
(2) 回帖