Scc Puzzle(AtCoder-2333)

Problem Description

Snuke loves puzzles.

Today, he is working on a puzzle using S- and c-shaped pieces. In this puzzle, you can combine two c-shaped pieces into one S-shaped piece, as shown in the figure below:

 

Snuke decided to create as many Scc groups as possible by putting together one S-shaped piece and two c-shaped pieces.

Find the maximum number of Scc groups that can be created when Snuke has NN S-shaped pieces and MM c-shaped pieces.

Constraints

  • 1≤N,M≤10121≤N,M≤1012

Input

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

N M

Output

Print the answer.

Example

Sample Input 1

1 6

Sample Output 1

2
Two Scc groups can be created as follows:

Combine two c-shaped pieces into one S-shaped piece
Create two Scc groups, each from one S-shaped piece and two c-shaped pieces

Sample Input 2

12345 678901

Sample Output 2

175897

题意:给出 n 个 s,m 个 c,已知两个 c 可以组成一个 s,问根据所给的 s 和 c 最多能组成多少个 scc

思路:

按题意模拟即可

一个 s 需要两个 c,那么 n 个 s 需要 2*n 个 c,且 4 个 c 可组成一个 scc,因此根据 2*n、m 的大小关系进行讨论:

  • n*2<=m 时:说明现有的 s 均能被选用,c 有多余,那么有 n 组 scc,此后计算剩余 c 的个数,除以 4 累加即可
  • n*2>m 时:说明现有的 c 均能被选用,s 有多余,那么有 m/2 组 scc

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
int main(){
    LL n,m;
    scanf("%lld%lld",&n,&m);

    LL res=0;
    if(n*2<=m){
        res+=n;
        m-=n*2;
        if(m>=4)
            res+=m/4;
    }
    else{
        res+=m/2;
    }
    printf("%lld\n",res);
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值