2020ICPC·小米 网络选拔赛热身赛

A

描述

提议描述

思路

f [ i ] [ j ] f[i][j] f[i][j]为放 i i i A A A, j j j B B B的合法方案数。
存在以下划分方式:
1. 1. 1. i < = n i<=n i<=n时,i可以随便放
2. 2. 2. j < = m j<=m j<=m时,j可以随便放
3. 3. 3. i > n i>n i>n时,由于 A B AB AB的数量要小于等于 n n n,则 i − j i-j ij为至少放了多少个 A B AB AB
4. 4. 4. j > m j>m j>m时,由于 B A BA BA的数量要小于等于 m m m,则 j − i j-i ji为至少放了多少个 B A BA BA

我们对第一种和第二种情况无需处理,只需要处理第三和第四种情况即可,得到转移方程
i f ( i − j > = n ) if(i-j>=n) if(ij>=n) f [ i ] [ j ] = ( f [ i ] [ j ] + f [ i − 1 ] [ j ] ) f[i][j]=(f[i][j]+f[i-1][j]) f[i][j]=(f[i][j]+f[i1][j])
i f ( j − i > = m ) if(j-i>=m) if(ji>=m) f [ i ] [ j ] = ( f [ i ] [ j ] + f [ i ] [ j − 1 ] ) f[i][j]=(f[i][j]+f[i][j-1]) f[i][j]=(f[i][j]+f[i][j1])
最后的 f [ n ] [ m ] f[n][m] f[n][m]即为我们的答案。

AC代码
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <set>
#include <stack>
#include <iomanip>
#define x first
#define y second
#define PB push_back
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define rep(x,l,u) for(ll x=l;x<u;x++)
#define rrep(x,l,u) for(ll x=l;x>=u;x--)
#define sz(x) x.size()
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define seteps(N) setprecision(N)
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<char,char> PCC;
typedef long long ll;
typedef pair<ll,ll> PLL;
typedef __int128 lll;
const int N=2*1010;
const int M=1e6+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const lll one=1;
ll f[N][N];
void solve(){
    double p=3.1415926;
    int n,m;
    while(cin>>n>>m){
        rep(i,0,n+m+1){
            rep(j,0,n+m+1){
                f[i][j]=0;
            }
        }
        f[0][0]=1;
        rep(i,0,n+m+1){
            rep(j,0,n+m+1){
                if(i>=1 && i-j<=n) f[i][j]=(f[i][j]+f[i-1][j])%mod;
                if(j>=1 && j-i<=m) f[i][j]=(f[i][j]+f[i][j-1])%mod;
            }
        }
        cout<<f[n+m][n+m]<<endl;
    }
}
int main(){
    IOS;
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    //int t;cin>>t;
    //while(t--)
    solve();
    return 0;
}

B

题意描述

题意描述

思路

对于每个数字,我们求出它的贡献。
1 , 2 , 1 , 3 1,2,1,3 1,2,1,3为例。
a [ 1 ] a[1] a[1] [ 1 , 1 ] , [ 1 , 2 ] , [ 1 , 3 ] , [ 1 , 4 ] [1,1],[1,2],[1,3],[1,4] [1,1],[1,2],[1,3],[1,4]中出现,且出现了 4 4 4次,贡献为 1 ∗ 4 1*4 14
a [ 2 ] a[2] a[2] [ 2 , 2 ] , [ 2 , 3 ] , [ 2 , 4 ] , [ 1 , 2 ] , [ 1 , 3 ] , [ 1 , 4 ] [2,2],[2,3],[2,4],[1,2],[1,3],[1,4] [2,2],[2,3],[2,4],[1,2],[1,3],[1,4]中出现,且出现了 6 6 6次。发现, a [ 2 ] a[2] a[2]在后面的 n − i + 1 n-i+1 ni+1个区间中都出现,如果再加上 2 2 2前面的 a [ 1 ] a[1] a[1],就又有了 n − i + 1 n-i+1 ni+1个贡献。
a [ 3 ] a[3] a[3] [ 3 , 3 ] , [ 3 , 4 ] , [ 1 , 3 ] , [ 1 , 4 ] , [ 2 , 3 ] , [ 2 , 4 ] [3,3],[3,4],[1,3],[1,4],[2,3],[2,4] [3,3],[3,4],[1,3],[1,4],[2,3],[2,4]中出现,且出现了 6 6 6次。但是 a [ 3 ] a[3] a[3] a [ 1 ] a[1] a[1]是相同的,实际贡献为 2 ∗ 3 − 2 ∗ 1 = 4 2*3-2*1=4 2321=4
a [ 4 ] a[4] a[4]同理。

我们发现,如果该数字是第一次出现,则该数字的贡献为左区间数 ∗ * 右区间数。否则数字贡献为当前下标和第一次出现该数字下标之间的位置 ∗ * 右区间数

AC代码
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <set>
#define x first
#define y second
#define PB push_back
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define rep(x,l,u) for(ll x=l;x<u;x++)
#define rrep(x,l,u) for(ll x=l;x>=u;x--)
#define sz(x) x.size()
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<char,char> PCC;
typedef long long ll;
typedef pair<ll,ll> PLL;
typedef __int128 lll;
const int N=2*1e5+10;
const int M=1e6+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const lll one=1;
int a[N];
void solve(){
    int n;
    cin>>n;
    rep(i,1,n+1) cin>>a[i];
    ll ans=0;
    map<int,int> used;
    rep(i,1,n+1){
        if(!used[a[i]]){
            ans+=(i*(n-i+1));
        }else{
            ans+=(n-i+1)*(i-used[a[i]]);
        }
        used[a[i]]=i;
    }
    cout<<ans<<endl;
}
int main(){
    IOS;
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    //int t;cin>>t;
    //while(t--)
    solve();
    return 0;
}

F

题意描述

题意描述

思路

判断 x ∗ b x*b xb a ∗ y a*y ay的大小即可。由于数据范围太大,可以使用JAVA的大整数和py或者C++的__int128来解决。

AC代码
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <set>
#define x first
#define y second
#define PB push_back
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define rep(x,l,u) for(ll x=l;x<u;x++)
#define rrep(x,l,u) for(ll x=l;x>=u;x--)
#define sz(x) x.size()
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<char,char> PCC;
typedef long long ll;
typedef pair<ll,ll> PLL;
typedef __int128 lll;
const int N=2*1e5+10;
const int M=1e6+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const lll one=1;
int a[N];
void solve(){
    ll a,b,x,y;
    while(cin>>x>>a>>y>>b){
        lll res1=one*x*b;
        lll res2=one*a*y;
        if(res1==res2) cout<<"="<<endl;
        else if(res1<res2) cout<<"<"<<endl;
        else cout<<">"<<endl;
    }
}
int main(){
    IOS;
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    //int t;cin>>t;
    //while(t--)
    solve();
    return 0;
}

G

题意描述

提议描述

思路

使用一个字符串来储存删除过后的字符串序列,使用一个变量来表示删除后的字符串下标。每次符合条件时,变量都要向前移3位,模拟这个过程即可。

AC代码
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <set>
#include <stack>
#define x first
#define y second
#define PB push_back
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define rep(x,l,u) for(ll x=l;x<u;x++)
#define rrep(x,l,u) for(ll x=l;x>=u;x--)
#define sz(x) x.size()
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<char,char> PCC;
typedef long long ll;
typedef pair<ll,ll> PLL;
typedef __int128 lll;
const int N=2*1e5+10;
const int M=1e6+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const lll one=1;
void solve(){
    string s,v;
    cin>>s;
    v=s;
    int now=0,ans=0;
    rep(i,0,sz(s)){
        now++;
        v[now]=s[i];
        if(now>=3 && v[now]==v[now-1] && v[now-2]==v[now]){
            ans++;
            now-=3;
        }
    }
    cout<<ans<<endl;
}
int main(){
    IOS;
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    //int t;cin>>t;
    //while(t--)
    solve();
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值