UESTC 2016 Summer Training #1 Div.2(未完待续)

由于时间紧张,先上代码,细节后续补充
题目来源:2016 PSUT Coding Marathon(GYM 100989)

A

#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
#define eps 1e-6
typedef long long LL;
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
using namespace std;


int main()
{
    //ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("int.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    scanf("%d",&n);
    printf("%d\n",n + 1);
    return 0;
}

B

#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
#define eps 1e-6
typedef long long LL;
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
using namespace std;

int R,C;
int dp[30][30];
int b[30];

int main()
{
    //ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("int.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    memset(b,0,sizeof(b));
    char s1[] = "abcdefghijklmnopqrstuvwxyz";
    char s2[30];
    cin >> R >> C;
    for(int i = 0;i <= R;i++)
        for(int j = 0;j <= C;j++)
            cin >> dp[i][j];
    for(int i = 1;i <= R;i++)
        for(int j = 1;j <= C;j++)
        {
            if(dp[i - 1][j - 1] == dp[i - 1][j] && dp[i - 1][j] == dp[i][j - 1] && dp[i][j - 1] == dp[i][j] - 1)
            {
                if(b[j - 1] == 0)
                {
                    s2[j - 1] = s1[i - 1];
                    b[j - 1] = 1;
                }
                else
                {
                    char s = s1[i - 1];
                    for(int i = 1;i <= R;i++)
                        if(s1[i - 1] == s)
                            s1[i - 1] = s2[j - 1];
                    for(int i = 1;i <= C;i++)
                        if(s2[i - 1] == s)
                            s2[i - 1] = s2[j - 1];
                }
            }
        }
    for(int j = 0;j < C;j++)
        if(b[j] == 0)
            s2[j] = 'z';
    for(int i = 0;i < R - 1;i++)
        printf("%c",s1[i]);
    printf("%c\n",s1[R - 1]);
    for(int i = 0;i < C - 1;i++)
        printf("%c",s2[i]);
    printf("%c\n",s2[C - 1]);
    return 0;
}

C

#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
#define eps 1e-6
typedef long long LL;
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
using namespace std;


int main()
{
    //ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("int.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    scanf("%d",&n);
    int ans = 0;
    int a,b;
    while(n--)
    {
        cin >> a >> b;
        ans += (b - a);
    }
    cout << ans << endl;
    return 0;
}

D

#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
#define eps 1e-6
typedef long long LL;
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
using namespace std;

int a[100005],b[100005];
string s1;
int k;
set<pair<int,int> > s;
set<pair<int,int> >::iterator it;

int main()
{
    //ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("int.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    memset(b,0,sizeof(b));
    int N,Q;
    scanf("%d %d",&N,&Q);
    for(int i = 1;i <= N;i++)
    {
        cin >> a[i];
        s.insert(make_pair(a[i],i));
    }
    while(Q--)
    {
        cin >> s1 >> k;
        if(s1 == "in")
        {
            if((it = s.lower_bound(make_pair(k,1))) == s.end())
            {
                puts("-1");
                continue;
            }
            else
                cout << it -> second << endl;
            s.erase(it);
        }
        else
            s.insert(make_pair(a[k],k));
    }
    return 0;
}

E

#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
#define eps 1e-6
typedef long long LL;
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
using namespace std;

string s1,s2;

int main()
{
    //ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("int.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    cin >> s1 >> s2;
    int ok = 0;
    if(s1.size() == s2.size())
    {
        int num = 0;
        for(int i = 0;i < s1.size();i++)
        {
            if(s1[i] != s2[i])
                num++;
        }
        if( num == 0 || (num == 1 && s1.size() >= 8) )
            ok = 1;
    }
    else if(s1.size() - s2.size() == 1 && s1.size() >= 8)
    {
        int i,j;
        for(i = 0,j = 0;i < s1.size() && j < s2.size();)
        {
            if(s1[i] == s2[j])
            {
                i++;
                j++;
            }
            else
                i++;
        }
        if(i - j == 1 || (i == j && i == s2.size()))
            ok = 1;
    }
    if(ok)
        puts("yes");
    else
        puts("no");
    return 0;
}

F

#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
#define eps 1e-6
typedef long long LL;
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
using namespace std;


int a[100005],b[100005];

int s,k;

int main()
{
    //ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("int.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    memset(b,0,sizeof(b));
    int N,M,Q;
    scanf("%d %d %d",&N,&M,&Q);
    int ans = 0;
    for(int i = 1;i <= N;i++)
    {
        cin >> a[i];
        b[a[i]]++;
        if(b[a[i]] == 1)
            ans++;
    }
    while(Q--)
    {
        cin >> s >> k;
        if(b[a[s]] == 1)
            ans--;
        b[a[s]]--;
        a[s] = k;
        b[a[s]]++;
        if(b[a[s]] == 1)
            ans++;
        printf("%d\n",M - ans);
    }
    return 0;
}

G

#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
#define eps 1e-6
typedef long long LL;
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
using namespace std;

LL a[100005];

bool cmp(const LL &a,const LL &b)
{
    return a > b;
}

int main()
{
    LL M,K;
    cin >> M >> K;
    LL sum = 0;
    for(LL i = 1;i <= M;i++)
    {
        scanf("%lld",&a[i]);
        sum += a[i];
    }
    LL ave = ceil(sum * 1.0 / M);
    sort(a + 1,a + M + 1,cmp);
    LL h = 0;
    LL ans = a[1];
    for(LL i = 1;a[i] > ave;i++)
    {
        if(K >= i * (a[i] - a[i + 1]))
        {
            K -= i * (a[i] - a[i + 1]);
            ans = a[i + 1];
        }
        else
        {
            ans = a[i] - K / i;
            break;
        }
    }
    cout << max(ans,ave) << endl;
    return 0;
}

H

#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
#define eps 1e-6
typedef long long LL;
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
using namespace std;

int K;
int F[10];
int a[] = {0,1,5,10,20,50};
int num[10];

int main()
{
    //ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("int.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int N;
    cin >> N;
    memset(num,0,sizeof(num));
    int ok = 1;
    while(N--)
    {
        cin >> K;
        int sum = 0;
        for(int i = 1;i <= 5;i++)
        {
            cin >> F[i];
            sum += F[i] * a[i];
        }
        //cout << sum << endl;
        if(sum == K)
        {
            for(int i = 1;i <= 5;i++)
                num[i] += F[i];
        }
        else
        {
            int ans = sum - K;
            //cout << ans << endl;
            for(int i = 5;i >= 1;i--)
            {
                while(ans > 0)
                {
                    if(ans >= a[i] && num[i] > 0)
                    {
                        ans -= a[i];
                        num[i]--;
                    }
                    else
                        i--;
                    if(i == 0)
                        break;
                }
                if(ans != 0)
                {
                    ok = 0;
                    break;
                }
            }
            //for(int i = 1;i < 5;i++)
               // printf("%d ",num[i]);
            //printf("%d\n",num[5]);
        }
    }
    if(ok)
        puts("yes");
    else
        puts("no");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值