苏州大学ICPC集训队新生赛第二场

A - Score

UVA - 1585

#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;
}

B - Tetrahedron

题意:四面体,从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;
}

fyh正解:dp;

这个很像dp,定义状态:  dp(i,j)为走i步,到了 j 点 ;

每走一步都受前面状态影响:转移方程为:    dp[i][j]+=dp[i-1][k];

#include<bits/stdc++.h>
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=1e7+5;
int dp[maxn][4];
int main(){
   int n;
   cin>>n;
   dp[0][0]=0;
   dp[1][1]=1;
   dp[1][2]=1;
   dp[1][3]=1;
   for(int i=2;i<=n;i++)
   for(int j=0;j<=3;j++){
   for(int k=0;k<=3;k++){
   if(j==k)continue;
   dp[i][j]+=dp[i-1][k];
   // else dp[i][j]=
   dp[i][j]%=MOD;
   }
   }
   cout<<dp[n][0]<<endl;
    return 0;
}

原文地址:https://www.cnblogs.com/littlerita/p/12375313.html

时间: 2024-08-30 00:19:36

苏州大学ICPC集训队新生赛第二场的相关文章

Contest1592 - 2018-2019赛季多校联合新生训练赛第二场(部分题解)

D 10248 修建高楼 D 传送门 题干 题目描述 C 市有一条东西走向的"市河".C 市的市长打算在"市河"的其中一条岸边自东往西的 n 个位置(可以将这 n 个位置看成在一条直线上,且位置不会重叠)依次建造高楼. C 市的设计部门设计了 T 个方案供市长挑选(方案编号为 1 到 T).每个方案都提供了建造的每幢高楼的高度,自东向西依次为 h1,h2,h3,-,hn-1,hn.每幢楼房的高度在 1 到 n 之间(包括 1 和 n),且各不相同. 市长在挑选设计方

集训队寒假集训第二场补题题解

补题什么的待填坑... A - Generous Kefa (语法基础) 直接开桶看看有没有超过三个的,因为题目明确提出没有气球也是可以的 代码 #include <bits/stdc++.h> using namespace std; int bk[123213]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,k; cin>>n>>k; string a; cin>&g

2017 多校赛 第二场

1003.Maximum Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Steph is extremely obsessed with “sequence problems” that are usually see

2015 多校赛 第二场 1006 (hdu 5305)

Problem Description There are n people and m pairs of friends. For every pair of friends, they can choose to become online friends (communicating using online applications) or offline friends (mostly using face-to-face communication). However, everyo

2015 多校赛 第二场 1002 (hdu 5301)

Description Your current task is to make a ground plan for a residential building located in HZXJHS. So you must determine a way to split the floor building with walls to make apartments in the shape of a rectangle. Each built wall must be paralled t

2015 多校赛 第二场 1004 hdu(5303)

Problem Description There are n apple trees planted along a cyclic road, which is L metres long. Your storehouse is built at position 0 on that cyclic road.The ith tree is planted at position xi, clockwise from position 0. There are ai delicious appl

2019 HDU 多校赛第二场 HDU 6598 Harmonious Army 构造最小割模型

题意: 有n个士兵,你可以选择让它成为战士还是法师. 有m对关系,u和v 如果同时为战士那么你可以获得a的权值 如果同时为法师,你可以获得c的权值, 如果一个为战士一个是法师,你可以获得b的权值 问你可以获得的最大权值是多少? 题解: 对每个士兵建立一个点x ,点x 向源点s 连一条边,向汇点t 连一条边, 分别表示选择两种职业,然后就可以先加上所有的贡献,通过两点关系用 最小割建模,如下图所示 设一条边的三种贡献为A, B, C,可以得到以下方程: 如果x,y都是法师,你可以获得C的权值,但是

2019个人训练赛第二场-A - BowWow and the Timetable

题意: 大概就是给你一串二进制的数,然后让你求log(4)s吧,刚开始找错方向,先把它转成十进制,结果数太大 解决方法: 大概是分析这个数如果正好是4的幂次方的话在二进制的表示里应该只有一个1,所以分析数的长度就可以 #include<bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; for(int i=1;i < s.size();i++){ if(s[i] == '1'){ cout<

CSP-S全国模拟赛第二场 【nan】

A.count 本场比赛最难的题... 隔板法组合数容斥 xjb 搞搞就好了 //by Judge #include<cstdio> #include<iostream> #define Rg register #define fp(i,a,b) for(Rg int i=(a),I=(b)+1;i<I;++i) #define fd(i,a,b) for(Rg int i=(a),I=(b)-1;i>I;--i) #define ll long long using