真的是很遗憾,本来47分是300名左右的,可以进入下一轮,但是自己忘记了把int该 成long long类型导致计算越界,出现了负数。我居然都没有检查输出文件,就直接交上去了,混蛋啊。。。。。
第一题:
注意不要重复计数就可以了。
#include <vector> #include <list> #include <limits.h> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <string.h> #include <stdlib.h> using namespace std; bool check(char a){ if(a=='a' || a=='e' || a=='i' || a=='o' || a=='u') return false; return true; } int main(){ freopen("A.in", "r", stdin); freopen("1.out", "w", stdout); int t, n; vector<int> start; string name; cin>>t; for(int j=1; j<=t; j++){ start.clear(); long long res = 0; cin>>name>>n; int counter = 0; int len = name.size(); for(int i=0; i<len; i++){ if(check(name[i])==false) counter = 0; else counter++; if(counter>=n) start.push_back(i); } for(int i=0; i<start.size(); i++){ long long left, right; if(i==0) left = start[i]-n+1+1; else left = start[i]-start[i-1]; if(i==start.size()-1) right = len - start[i]; else right = len-start[i]; //cout<<left<<" "<<right<<endl; res += left*right; } cout<<"Case #"<<j<<": "<<res<<endl; } return 0; }
第二题small input:
采用构造的方法,要向东走1单位,只需要想跳到西边去,紧接着跳到东边去,向北走的情形也是类似的。
#include <vector> #include <list> #include <limits.h> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <string.h> #include <stdlib.h> using namespace std; int main(){ freopen("1.in", "r", stdin); freopen("1.out", "w", stdout); int t, x, y; vector<char> res; cin>>t; for(int i=1; i<=t; i++){ cin>>x>>y; res.clear(); if(x>0){ for(int j=0; j<x; j++){ res.push_back('W'); res.push_back('E'); } } else{ for(int j=0; j<-x; j++){ res.push_back('E'); res.push_back('W'); } } if(y>0){ for(int j=0; j<y; j++){ res.push_back('S'); res.push_back('N'); } } else{ for(int j=0; j<-y; j++){ res.push_back('N'); res.push_back('S'); } } cout<<"Case #"<<i<<": "; for(int j=0; j<res.size(); j++) cout<<res[j]; cout<<endl; } return 0; }
第三题small input:
一天一天的模拟就行了,注意数组下表可能取负数的情形。
#include <vector> #include <list> #include <limits.h> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <string.h> #include <stdlib.h> using namespace std; struct Node{ int di, ni, wi, ei; int si, delta_di, delta_pi, delta_si; }; Node node[20]; int main(){ //freopen("1.in", "r", stdin); //freopen("1.out", "w", stdout); int t, n; int wall[1000005]; int middle[1000005]; cin>>t; for(int j=1; j<=t; j++){ int res = 0; int days = 0; int offset = 500000; memset(wall, 0, sizeof(wall)); memset(middle, 0, sizeof(middle)); cin>>n; for(int i=0; i<n; i++){ cin>>node[i].di>>node[i].ni>>node[i].wi>>node[i].ei >>node[i].si>>node[i].delta_di>>node[i].delta_pi>>node[i].delta_si; days = max(days, node[i].di+node[i].ni*node[i].delta_di); } vector<pair<int, int> > v; vector<int> height; for(int i=0; i<=days; i++){ v.clear(); height.clear(); for(int cur=0; cur<n; cur++){ if(node[cur].ni<=0 || node[cur].di>i) continue; if((i-node[cur].di)%(node[cur].delta_di)!=0) continue; int start = node[cur].wi; int end = node[cur].ei; bool okay = false; for(int k=start; k<=end; k++){ if(wall[offset+k]<node[cur].si){ okay=true; v.push_back(make_pair(start, end)); //cout<<"start: "<<start<<" end: "<<end<<endl; height.push_back(node[cur].si); break; } if(k!=end && middle[offset+k]<node[cur].si){ okay = true; v.push_back(make_pair(start, end)); //cout<<"start: "<<start<<" end: "<<end<<endl; height.push_back(node[cur].si); break; } } node[cur].ni--; node[cur].si += node[cur].delta_si; node[cur].wi += node[cur].delta_pi; node[cur].ei += node[cur].delta_pi; if(okay==true) res++; } int len = v.size(); for(int k=0; k<len; k++){ int start = v[k].first; int end = v[k].second; for(int ii=start; ii<=end; ii++){ wall[ii+offset] = max(wall[ii+offset], height[k]); if(ii != end) middle[ii+offset] = max(middle[ii+offset], height[k]); } } } cout<<"Case #"<<j<<": "<<res<<endl; } return 0; }