AtCoder Beginner Contest 247

9 篇文章 1 订阅

AtCoder Beginner Contest 247

B - Unique Nicknames

#include <bits/stdc++.h>

#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }

const int maxn = 1e2 + 10;
const int N = 6e6 + 100;

int dp[maxn][maxn][maxn][maxn];
int a[maxn][maxn];
int v[maxn];

map<string,int> mp;
string s[101];
string t[101];

void solve() {
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i) {
        cin>>s[i]>>t[i];
        mp[s[i]]++,mp[t[i]]++;
        if(s[i]==t[i]) mp[s[i]]--;
    }
    for (int i = 0; i < n; ++i) {
        if(mp[s[i]]>1&&mp[t[i]]>1){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
}

signed main() {
    //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();//cout<<"\n";
    }
    return 0;
}

//12341
//14321
//

C - 1 2 1 3 1 2 1

#include <bits/stdc++.h>

#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }

const int maxn = 1e2 + 10;
const int N = 6e6 + 100;

int dp[maxn][maxn][maxn][maxn];
int a[maxn][maxn];
int v[maxn];

map<string,int> mp;
string s[101];
string t[101];

void dfs(int n){
    if(n<1) return;
    dfs(n-1);
    cout<<n<<" ";
    dfs(n-1);
}

void solve() {
    int n;
    cin>>n;
    dfs(n);
}

signed main() {
    //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();//cout<<"\n";
    }
    return 0;
}

//12341
//14321
//

D - Cylinder

#include <bits/stdc++.h>

#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }

const int maxn = 1e2 + 10;
const int N = 6e6 + 100;

int dp[maxn][maxn][maxn][maxn];
int a[maxn][maxn];
int v[maxn];

queue<pair<int,int>> que;


void solve() {
    int n;
    cin>>n;
    while (n--){
        int t,x,c;
        cin>>t;
        if(t==1){
            cin>>x>>c;
            que.push({c,x});
        }else{
            cin>>c;
            int sum=0;
            while (c>0){
                auto &[cc,xx] = que.front();
                sum+=min(cc,c)*xx;
                c-=cc,cc=-c;
                if(cc<0) que.pop();
            }
            cout<<sum<<endl;
        }
    }
}

signed main() {
    //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();//cout<<"\n";
    }
    return 0;
}

//12341
//14321
//

E - Max Min

容斥

#include <bits/stdc++.h>

#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }

const int maxn = 1e6 + 10;
const int N = 6e6 + 100;

int dp[maxn];
int a[maxn];
int v[maxn];

int n,y,x;
int getNum(int l,int r){
    int res=0,len=0;
    for (int i = 0; i < n; ++i) {
        if(a[i]<l||a[i]>r){
            res+=(len+1)*len/2;
            len=0;
        } else{
            len++;
        }
    }
    if(len) res+=(len+1)*len/2;
    return res;
}

void solve() {
    cin>>n>>x>>y;
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    cout<<getNum(y,x)-getNum(y+1,x)-getNum(y,x-1)+getNum(y+1,x-1)<<endl;
}

signed main() {
    //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();//cout<<"\n";
    }
    return 0;
}

//12341
//14321
//

dp

#include <bits/stdc++.h>

#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }

const int maxn = 1e6 + 10;
const int N = 6e6 + 100;

int dp[maxn][3][3];
int a[maxn];
int v[maxn];

int n,y,x;

void solve() {
    cin>>n>>x>>y;
    int ans=0;
    for (int i = 1; i <=n; ++i) {
        cin>>a[i];
    }
    for (int i = 1; i <=n; ++i) {
        if(a[i]<y||a[i]>x) continue;
        int l=a[i]==y,r=a[i]==x;
        dp[i][l][r]+=1;
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                dp[i][l|j][r|k]+=dp[i-1][j][k];
            }
        }
        ans+=dp[i][1][1];
    }
    cout<<ans;
}

signed main() {
    //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();//cout<<"\n";
    }
    return 0;
}

//12341
//14321
//

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值