CF227 Div2 (D)

A. George and Sleep

输入连个时间 A,B,其中A表示起床时间,B表示睡了多长时间,求几点开始睡

input
05:50
05:44
output
00:06
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<ctype.h>
#include<algorithm>
#include<string>
#define PI acos(-1.0)
#define maxn 1000
#define INF 1<<25
#define mem(a, b) memset(a, b, sizeof(a))
typedef long long ll;
using namespace std;
int main ()
{
    int ch, cm, a, b;
    char str[100];
    gets(str);
    sscanf(str, "%d:%d", &ch, &cm);
    gets(str);
    sscanf(str, "%d:%d", &a, &b);
    b = cm - b;
    if (b < 0) b += 60, ch--;
    a = ch - a;
    if (a < 0) a += 24;
    printf("%02d:%02d\n",a, b);
    return 0;
}

B George and Round

输入n,m。其中n为比赛需要的题目数,而m为题库的题目数,接下来输入n个数字,代表比赛题目的难度,另起一行再输入m个数字,代表题库中题目难度。George只能将题库中的题目难度降低,现在要问他从题库中选完题目之后,还需要自己再多出几道题目。

input
3 5
1 2 3
1 1 1 1 1
output
2
int main ()
{
    int n, m, a[3100], i, j;
    cin>>n>>m;
    for (i = 0; i < n; i++)
        cin>>a[i];
    j = 0;
    int t;
    for (i = 0; i < m; i++)
    {
        cin>>t;
        if (t >= a[j] && j < n) j++;
    }
    cout<<n - j<<endl;
    return 0;
}


C. George and Number

有一个数组 b ,每次可以进行如下操作:

取出两个数,且 bi ≥ bj.。然后两个数连起来,如concat(500, 10) = 50010,再将新的数字放入数组中。

如此循环,直到数组中只剩下一个数p。

现在输入一个数p (1 ≤ p < 10100000)。

问一开始数组当中最多能有几个数字。


input
9555
output
4
如上述例子,可以拆分为 9, 5, 5, 5


这道题目其实可以从p的末尾开始,找到第一个非零的数字,如:1230560,找到6,然后从这里将数字分为两半,如果前面半段的长度大于后半段,一定可以拆分,如果长度相同,比较两个数的首位,因为后半段的数字除了首位都是0。


char str[100010];
bool flag = true;
int main ()
{
    gets(str);
    int len = strlen(str);
    int n = 0;
    while(flag)
    {
        char a[100010], b[100010];
        int j = len;
        while(str[j-1] == '0' && j) j--;
        j = j - 1;
        if (j == 0) flag = false;
        else
        {
            if (j > len - j)
            {
                len = j;
                n++;
            }
            else if (j == len - j)
            {
                int k, ok = 1;
                for (k = 0; k < j; k++)
                    if (str[k] < str[j + k])
                    {
                        ok = 0;
                        break;
                    }
                if (ok)
                {
                    n++;
                    len = j;
                }
                else flag = false;
            }
            else flag = false;
        }
    }
    n++;
    cout<<n<<endl;
    return 0;
}



E. George and Cards

有一堆纸牌,共N张,数字分别为1到N,以任意顺序从左到右排在桌上。现在要从中保留K张纸牌,告诉你它们从左到右的排列书序(保证是之前的子集)。

现在以下的操作:

每次从已有的纸牌堆中选取一个连续子段(假设长度为w),然后将这个子段当中最小的一张牌取出。每次操作可以得到w分。

经过N-K次操作之后,问得到的分数最大为多少。

input
10 5
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10
output
30
如上述样例,先取子段 {1 2 3 4 5 6 7 8 9 10} ,取出1, w = 10; 再取{3 4 5 6 7 8 9 10}, 取出3, w = 8; {5 6 7 8 9 10} 取出5, w = 6; {7 8 9 10} 取出7, w = 4; {9 10} 取出9, w = 2。总得分为30

这道题目可以确定,一定是按照从小到大的顺序取走不用的卡片。

在取 i 时,子段的左右两边都是比 i 小的且是要保留的数(因为比 i 小的不用保留的数已经取走了) (我们可以在纸牌的左右两端假想有两张不能取走的牌,数字为0)

所以可以开一个p数组记录位置。开一个set 来存放需要保留的卡片的位置,一开始将0 和 N+1 也加入到set中。

从1 到 n 进行遍历,如果是需要的卡片,则将位置加入到set当中,如果是不需要的卡片,就从set当中找出位于该卡片左右两端卡片的位置,两者之差的卡片数即为w。

再用一个树状数组来维护卡片数。

#include<iostream>
#include<fstream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<ctype.h>
#include<algorithm>
#include<string>
#define PI acos(-1.0)
#define maxn 1000100
#define INF 1<<25
#define mem(a, b) memset(a, b, sizeof(a))
typedef long long ll;
using namespace std;
int n, k, p[maxn], b[maxn], s[maxn];
ll ans;
void add(int x, int t)
{
    while(x <= n)
    {
        s[x] += t;
        x += x & -x;
    }
}
int sum(int x)
{
    int d = 0;
    while(x > 0)
    {
        d += s[x];
        x -= x & -x;
    }
    return d;
}
set<int> F;
int main ()
{
    cin>>n>>k;
    F.insert(0), F.insert(n + 1);
    for (int i = 1, x; i <= n; i++)
    {
        scanf("%d", &x);
        p[x] = i;
        add(i, 1);
    }
    for (int i = 1, x; i <= k; i++)
    {
        scanf("%d", &x);
        b[x] = 1;
    }
    for (int i = 1; i <= n; i++) if (b[i]) F.insert(p[i]);
    else
    {
        set<int>::iterator x, y;
        x = F.lower_bound(p[i]);
        y = x--;
        ans += sum(*y - 1) - sum(*x);
        add(p[i], -1);
    }
    cout<<ans<<endl;
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<div id="wea_rich_text_default_font" style="font-family:微软雅黑;font-size:12;"><p><img alt="" src="/weaver/weaver.file.FileDownload?fileid=aaa9aee4717d33272bd7ea028fa03118b693919f23b18febf9f6cee1158e8f4cf027542c71c8cf98d63770ccdf3bd1750e6b92e28c43dccd4" /></p><div class="ckeditor-html5-video" data-widget="html5video" style="text-align:left"><video controls="controls" src="/weaver/weaver.file.FileDownload?fileid=aad6f413f83191673980c5ee24b412880d6b9e8703caca411faec3276fe8133f5fa7e34630ca89ace63770ccdf3bd175071362141037cfb4e&download=1" style="max-width:100%"> </video></div><table border="1" cellpadding="1" style="width:500px;"> <tbody> <tr> <td style="padding: 1px;">1</td> <td style="padding: 1px;">1</td> </tr> <tr> <td style="padding: 1px;">2</td> <td style="padding: 1px;">2</td> </tr> <tr> <td style="padding: 1px;">3</td> <td style="padding: 1px;">3<a href="http://localhost:8080/wui/index.html#/main/portal/portal-1-1?menuIds=0,1&menuPathIds=0,1&_key=zq8830" target="_blank">http://localhost:8080/wui/index.html#/main/portal/portal-1-1?menuIds=0,1&menuPathIds=0,1&_key=zq8830</a></td> </tr> </tbody></table><p>测试<a href="http://localhost:8080/wui/index.html#/main/portal/portal-1-1?menuIds=0,1&menuPathIds=0,1&_key=zq8830" target="_blank">http://localhost:8080/wui/index.html#/main/portal/portal-1-1?menuIds=0,1&menuPathIds=0,1&_key=zq8830</a></p><p> </p><p>修改一下吧 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq<img alt="" src="/weaver/weaver.file.FileDownload?fileid=a7617945ec5f52ec80aaa43ee8504de0a1b14d5eca4a98834494c85349762c626dec7ba8d0da277106ee600d27743f4e44f710fbddd167603" /></p></div>
06-01

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值