t1切圆 cut
#include<cstdio> using namespace std; long long n; int main(){ freopen("cut.in","r",stdin); freopen("cut.out","w",stdout); scanf("%lld",&n); printf("%lld",n*(n+1)/2+1); return 0; }
t2 play
#include<cstdio> #include<cstring> using namespace std; int n,m,xa,ya,xb,yb,l,ans=1;char c[2005][2005],s[5005];bool f; int dx[]={0,0,-1,1},dy[]={-1,1,0,0}; int go(char a){ switch(a){ case 'a':return 0; case 'd':return 1; case 'w':return 2; case 's':return 3; } } int main(){ freopen("play.in","r",stdin); freopen("play.out","w",stdout); scanf("%d%d",&n,&m); for(int i=1;i<=n;++i){ scanf("%s",c[i]+1); if(!xa||!xb) for(int j=1;j<=m;++j) switch(c[i][j]){ case 'a':c[xa=i][ya=j]='#';break; case 'b':xb=i;yb=j;break; } } scanf("%s",s); l=strlen(s); for(int i=0;i<l;++i){ int x=xa+dx[go(s[i])],y=ya+dy[go(s[i])]; if(x && x<=n && y && y<=m && c[x][y] != '*'){ xa=x,ya=y; if(x==xb && y==yb) f=1; if(c[x][y] != '#') ++ans,c[x][y]='#'; } } printf("%d\n",ans); f?printf("YES"):printf("NO"); return 0; }
t3 计蒜客
//栈的基础练习 #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<queue> #include<stack> using namespace std; stack<int> sa; stack<char> st; int val[505],ans,n; char s[305]; void init(){ val['*'] = 2; val['/'] = 2; val['+'] = 1; val['-'] = 1; } int main(){ init(); scanf("%d%s",&n,s+1); int len = strlen(s+1); s[0] = '('; s[len+1] = ')'; for(int i = 0; i <= len+1; i++){ // cout<<"chu: "<<i<<" "<<s[i]<<endl; if(s[i] == '('){ st.push(s[i]);//如果是左括号,则直接入栈 // cout<<"fuhao: "<<s[i]<<endl; } else if(s[i] >= '0' && s[i] <= '9'){ int tmp = s[i] - '0'; int j = i; while(s[j+1] >= '0' && s[j+1] <= '9'){ j++; tmp = tmp * 10 + s[j] - '0'; } i = j; sa.push(tmp); // cout<<"i:"<<i<<endl; }else{ while(!st.empty() && val[s[i]] <= val[st.top()]){//如果当前符号<= // cout<<"youxianjipanduan: "<<s[i]<<""<<val[s[i]]<<" "<<st.top()<<" "<<val[st.top()]<<endl; if(st.top() == '('){//特判:如果栈定是左括号,就不进行计算了 if(s[i] == ')') st.pop(); break; } int xa = sa.top(); sa.pop(); int xb = sa.top(); sa.pop(); int xc = 0; char sig = st.top(); st.pop(); if(sig == '*') xc = xb * xa; else if(sig == '/') xc = xb / xa; else if(sig == '+') xc = xb + xa; else if(sig == '-') xc = xb - xa; // cout<<"youxianji: "<<xc<<endl; ans = xc; sa.push(xc); } if(s[i] != ')') st.push(s[i]); // cout<<"fuhao: "<<s[i]<<endl; // if(st.empty()|| val[s[i]] > val[st.top()]) // st.push(s[i]); } } // cout<<"end:"<<endl; // while(!sa.empty()){ // cout<<sa.top()<<endl; // sa.pop(); // } // while(!st.empty()){ // cout<<st.top()<<endl; // st.pop(); // } cout<<ans<<endl; return 0; } // 31+(10-2*3+4)/3 // 31+8/3 // //1+(17*2+5-13/4)/4-16/2 //10-16/2