【CodeForces】[651A]Joysticks

来源:互联网 发布:青岛seo 编辑:程序博客网 时间:2024/05/01 06:01

这里写图片描述
这里写图片描述

大意是两个操纵杆一个充电器
每一个分钟只能充一个,充的那个电量+1不充的那个电量-2
需要注意的是
当有一个电量为1时则必须要充
否则就游戏结束
当然 当有电量为0的游戏也结束

所以可以模拟来做
并且考虑一下特殊情况就好了

#include<stdio.h>int main() {    int n,m;    while(scanf("%d %d",&n,&m)!=EOF) {        int cnt=0;        while(n&&m) {            if(n==1&&m>1) {                n++;                m-=2;                cnt++;            } else if(m==1&&n>1) {                m++;                n-=2;                cnt++;            } else if(n==1&&m==1) {                n=0;                m=0;            } else {                if(n>m) {                    int t=(n-m)/2;                    if((n-m)&1)                        t++;                    n-=2*t;                    m+=t;                    cnt+=t;                } else if(m>n) {                    int t=(m-n)/2;                    if((m-n)&1)                        t++;                    m-=2*t;                    n+=t;                    cnt+=t;                } else {                    n-=2;                    m++;                    cnt++;                }            }        }        printf("%d\n",cnt);    }    return 0;}

题目地址:【CodeForces】[651A]Joysticks

0 0
原创粉丝点击