苏州大学ICPC集训队新生赛第二场
作者:互联网
A - Score
水
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; while(n--){ int sum=0; string s; cin>>s; int len=s.size(); int tmp=0; for(int i=0;i<len;i++){ if(s[i]=='O')sum+=tmp,tmp++; else { sum+=tmp; tmp=0; } } sum+=tmp; cout<<sum<<endl; } return 0; }View Code
题意:四面体,从D走n-1步回到D点,问你有多少种走法,数据量1e7;
标准错误解法:广搜:
#include<iostream> #include<queue> using namespace std; #define rep(i,j,k) for(int i=(int)j;i<=(int)k;i++) #define per(i,j,k) for(int i=(int)k;i>=(int)j;i--) #define pb push_back #define pf push_front #define fi first #define se second 11 typedef long long ll; typedef unsigned long long ull; typedef long double ldb; typedef double db; // const db PI=acos(-1.0); const ll INF=0x3f3f3f3f3f3f3f3fLL; const int inf=0x3f3f3f3f;//0x7fffffff; const double eps=1e-9; const ll MOD=1e9+7; const int maxn=1e3+5; ll n,ans; struct node{int id;ll step;node(int x,ll y){id=x,step=y;}}; void bfs(){ queue<node>Q; Q.push(node(4,0)); while(!Q.empty()){ node tmp=Q.front(); Q.pop(); if(tmp.step==n&&tmp.id==4){ ans++; } if(tmp.id==1&&tmp.step<n){ int t=(tmp.step+1)%MOD; Q.push(node(2,t)); Q.push(node(3,t)); Q.push(node(4,t)); } if(tmp.id==2&&tmp.step<n){ int t=(tmp.step+1)%MOD; Q.push(node(3,t)); Q.push(node(4,t)); Q.push(node(1,t)); } if(tmp.id==3&&tmp.step<n){ int t=(tmp.step+1)%MOD; Q.push(node(1,t)); Q.push(node(2,t)); Q.push(node(4,t)); } if(tmp.id==4&&tmp.step<n){ int t=(tmp.step+1)%MOD; Q.push(node(1,t)); Q.push(node(2,t)); Q.push(node(3,t)); } } } int main(){ cin>>n; ans=0; bfs(); cout<<ans<<endl; // system("pause"); return 0; }View Code
fyh正解:dp;
标签:tmp,集训队,const,int,ll,long,ICPC,苏州大学,define 来源: https://www.cnblogs.com/littlerita/p/12375313.html