2021-01-29

问题 A: 校门外的树

时间限制: 1 Sec  内存限制: 256 MB
提交 状态

题目描述

某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米。我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置;数 轴上的每个整数点,即0,1,2,……,L,都种有一棵树。
由于马路上有一些区域要用来建地铁。这些区域用它们在数轴上的起始点和终止点表示。已 知任一区域的起始点和终止点的坐标都是整数,区域之间可能有重合的部分。现在要把这些区域中的树(包括区域端点处的两棵树)移走。你的任务是计算将这些树 都移走后,马路上还有多少棵树。

输入

第一行有两个整数L(1<=L<=10000)和M(1<=M<=100),L代表马路的长度,M代表区域的数目,L和M之间用一个空格隔开。接下来的M行每行包含两个不同的整数,用一个空格隔开,表示一个区域的起始点和终止点的坐标。

输出

仅一行,只包含一个整数,表示马路上剩余的树的数目。

样例输入 Copy

500 3
150 300
100 200
470 471

样例输出 Copy

298

提示

对于20%的数据,区域之间没有重合的部分;
对于其它的数据,区域之间有重合的情况。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int a[10005] = {0};

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);
    int n,m; cin>>n>>m;
    for(int i = 0; i <= n; i++) a[i] = 1;

    int s,e;
    while(m--)
    {
        cin>>s>>e;
        if(s > e) swap(s, e);
        for(int i = s; i <= e; i++) a[i] = 0;
    }
    int ans = 0;
    for(int i = 0; i <= n; i++)
    {
        if(a[i]) ans++;
    }
    cout<<ans<<'\n';
    return 0;
}

 

问题 B: 陶陶摘苹果

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

陶陶家的院子里有一棵苹果树,每到秋天树上就会结出10个苹果。苹果成熟的时候,陶陶就会跑去摘苹果。陶陶有个30厘米高的板凳,当她不能直接用手摘到苹果的时候,就会踩到板凳上再试试。

现在已知10个苹果到地面的高度,以及陶陶把手伸直的时候能够达到的最大高度,请帮陶陶算一下她能够摘到的苹果的数目。假设她碰到苹果,苹果就会掉下来。

输入

输入包括两行数据。第一行包含10个100到200之间(包括100和200)的整数(以厘米为单位)分别表示10个苹果到地面的高度,两个相邻的整数之间用一个空格隔开。第二行只包括一个100到120之间(包含100和120)的整数(以厘米为单位),表示陶陶把手伸直的时候能够达到的最大高度。

输出

输出包括一行,这一行只包含一个整数,表示陶陶能够摘到的苹果的数目。

样例输入 Copy

100 200 150 140 129 134 167 198 200 111
110

样例输出 Copy

5

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);
    int a[15] = {0};
    for(int i = 1; i <= 10; i++) cin>>a[i];
    int n; cin>>n; n += 30;
    int ans = 0;
    for(int i = 1; i <= 10; i++)
    {
        if(a[i] <= n) ans++;
    }
    cout<<ans<<'\n';
    return 0;
}

 

问题 C: 采药

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师。为此,他想拜附近最有威望的医师为师。医师为了判断他的资质,给他出了一个难题。医师把他带 到一个到处都是草药的山洞里对他说:“孩子,这个山洞里有一些不同的草药,采每一株都需要一些时间,每一株也有它自身的价值。我会给你一段时间,在这段时 间里,你可以采到一些草药。如果你是一个聪明的孩子,你应该可以让采到的草药的总价值最大。”
如果你是辰辰,你能完成这个任务吗?

输入

输入的第一行有两个整数T(1 <= T <= 1000)和M(1 <= M <= 100),用一个空格隔开,T代表总共能够用来采药的时间,M代表山洞里的草药的数目。接下来的M行每行包括两个在1到100之间(包括1和100)的整 数,分别表示采摘某株草药的时间和这株草药的价值。

输出

输出包括一行,这一行只包含一个整数,表示在规定的时间内,可以采到的草药的最大总价值。

样例输入 Copy

70 3
71 100
69 1
1 2

样例输出 Copy

3

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int t[105] = {0};
int v[105] = {0};
int dp[1005] = {0};

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);
    int T,M; cin>>T>>M;

    for(int i = 1; i <= M; i++) cin>>t[i]>>v[i];

    for(int i = 1; i <= M; i++)
    {
        for(int j = T; j >= t[i]; j--)
        {
            dp[j] = max(dp[j], dp[j - t[i]] + v[i]);
        }
    }
    cout<<dp[T]<<'\n';
    return 0;
}

 

问题 E: AtCoDeer and Paint Cans

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.

Constraints
1≤a,b,c≤100

输入

The input is given from Standard Input in the following format:
a b c

输出

Print the number of different kinds of colors of the paint cans.

样例输入 Copy

3 1 4

样例输出 Copy

3

提示

Three different colors: 1, 3, and 4.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);
    int a[105] = {0};
    int t;
    for(int i = 1; i <= 3; i++)
    {
        cin>>t; a[t]++;
    }
    int ans = 0;
    for(int i = 1; i <= 100; i++)
    {
        if(a[i]) ans++;
    }
    cout<<ans<<'\n';
    return 0;
}

 

问题 F: Painting Balls with AtCoDeer

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors.
Find the number of the possible ways to paint the balls.

Constraints
1≤N≤1000
2≤K≤1000
The correct answer is at most 231−1.

输入

The input is given from Standard Input in the following format:
N K

输出

Print the number of the possible ways to paint the balls.

样例输入 Copy

2 2

样例输出 Copy

2

提示

We will denote the colors by 0 and 1. There are two possible ways: we can either paint the left ball in color 0 and the right ball in color 1, or paint the left in color 1 and the right in color 0.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);
    int n,m; cin>>n>>m;
    long long ans = 1;
    for(int i = 1; i <= n; i++)
    {
        if(i == 1) ans *= m;
        else ans *= (m - 1);
    }
    cout<<ans<<'\n';
    return 0;
}

 

问题 G: AtCoDeer and Election Report

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he checked it for the i-th (1≤i≤N) time, the ratio was Ti:Ai. It is known that each candidate had at least one vote when he checked the report for the first time.
Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time. It can be assumed that the number of votes obtained by each candidate never decreases.

Constraints
1≤N≤1000
1≤Ti,Ai≤1000(1≤i≤N)
Ti and Ai (1≤i≤N) are coprime.
It is guaranteed that the correct answer is at most 1018.

输入

The input is given from Standard Input in the following format:
N
T1 A1
T2 A2
:
TN AN

输出

Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N-th time.

样例输入 Copy

3
2 3
1 1
3 2

样例输出 Copy

10

提示

When the numbers of votes obtained by the two candidates change as 2,3→3,3→6,4, the total number of votes at the end is 10, which is the minimum possible number.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);
    int n; cin>>n;

    long long mid; long long x = 1; long long y = 1;
    int a,b;
    while(n--)
    {
        cin>>a>>b;
        mid = max(x / a, y / b);
        while(mid * a < x || mid * b < y) mid++;
        x = mid * a;
        y = mid * b;
    }
    cout<<x + y<<'\n';
    return 0;
}

 

问题 H: AtCoDeer and Rock-Paper

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two gestures, Rock and Paper, as in Rock-paper-scissors, under the following condition:
(※) After each turn, (the number of times the player has played Paper)≤(the number of times the player has played Rock).
Each player's score is calculated by (the number of turns where the player wins) − (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors.
(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)
With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score.
The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≤i≤N) character in s is g, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≤i≤N) character of s in p, TopCoDeer will play Paper in the i-th turn.

Constraints
1≤N≤105
N=|s|
Each character in s is g or p.
The gestures represented by s satisfy the condition (※).

输入

The input is given from Standard Input in the following format:
s

输出

Print the AtCoDeer's maximum possible score.

样例输入 Copy

gpg

样例输出 Copy

0

提示

Playing the same gesture as the opponent in each turn results in the score of 0, which is the maximum possible score.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);
    string s; cin>>s; int ls = s.size();
    
    int r1 = 0; int p1 = 0;
    int r2 = ls - ls / 2; int p2 = ls / 2;
    
    for(int i = 0; i <= ls - 1; i++)
    {
        if(s[i] == 'g') r1++;
        if(s[i] == 'p') p1++;
    }

    int ans = (p2 - p1);
    cout<<ans<<'\n';
    return 0;
}

 

问题 L: Social Distancing II

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

Despite his best attempt at making his N cows (1≤N≤1000) practice "social distancing", many of them still unfortunately contracted the disease. The cows, conveniently numbered 1…N, are each standing at distinct points along a long path (essentially a one-dimensional number line), with cow i standing at position xi. Farmer John knows that there is a radius R such that any cow standing up to and including R units away from an infected cow will also become infected (and will then pass the infection along to additional cows within R units away, and so on).

Unfortunately, Farmer John doesn't know R exactly. He does however know which of his cows are infected. Given this data, please determine the minimum possible number of cows that were initially infected with the disease.

输入

The first line of input contains N. The next N lines each describe one cow in terms of two integers, x and s, where x is the position (0≤x≤106), and s is 0 for a healthy cow or 1 for a sick cow. At least one cow is sick, and all cows that could possibly have become sick from spread of the disease have now become sick.

输出

Please output the minimum number of cows that could have initially been sick, prior to any spread of the disease.

样例输入 Copy

6
7 1
1 1
15 1
3 1
10 0
6 1

样例输出 Copy

3

提示

In this example, we know that R<3 since otherwise the cow at position 7 would have infected the cow at position 10. Therefore, at least 3 cows must have started out infected -- one of the two cows at positions 1 and 3, one of the two cows at positions 6 and 7, and the cow at position 15.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

typedef struct
{
    int p;
    int b;
}Cow;

Cow a[1005];

bool cmp(Cow a, Cow b)
{
    return a.p < b.p;
}

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);
    
    int n; cin>>n;
    for(int i = 1; i <= n; i++)
    {
        cin>>a[i].p>>a[i].b;
    }
    a[0].p = 0; a[0].b = 0;
    sort(a + 1, a + 1 + n, cmp);
//    for(int i = 1; i <= n; i++) cout<<a[i].p<<' ';
    int min = 1e6 + 5;
    
    for(int i = 2; i <= n; i++)
    {
        if(!a[i].b && a[i - 1].b)
        {
            if(min > (a[i].p - a[i - 1].p - 1))
            {
                min = (a[i].p - a[i - 1].p - 1);
            }
        }
        if(a[i].b && !a[i - 1].b)
        {
            if(min > (a[i].p - a[i - 1].p - 1))
            {
                min = (a[i].p - a[i - 1].p - 1);
            }
        }
    }
//    cout<<min<<'\n';
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        if(a[i].b && a[i - 1].b)
        {
            if((a[i].p - a[i - 1].p - 1) >= min)
            {
                ans++;
//                cout<<i<<'\n';
            }
        }
        if(a[i].b && !a[i - 1].b)
        {
            ans++;
//            cout<<i<<'\n';
        }
    }
    cout<<ans<<'\n';
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值