CodeForces 735

A Ostap and Grasshopper

题意和思路:给出蚱蜢的每次跳动的距离k,每次只能向左或者向右跳,根据路径上的情况可得出蚱蜢和昆虫(均有且仅有一个)的位置,如果蚱蜢和昆虫之间的距离不是k的倍数一定不行,若是则便利一遍看看路上是不是有障碍即可。

#include <iostream>
#include <iomanip>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <deque>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>

#define debug(x) cout << "--------------> " << x << endl

using namespace std;

const int MAXN = 1000 + 7;

int main()
{
        int n, k;
        cin >> n >> k;
        string str;
        cin >> str;
        int st, en;
        st = en = 0;
        for(int i = 0; str[i]; ++i)
        {
                if(str[i] == 'G')
                        st = i;
                if(str[i] == 'T')
                        en = i;
        }
        //cout << st << "  " << en << endl;
        bool flag = false;
        if(abs(en - st) % k != 0)
        {
                cout << "NO" << endl;
        }
        else
        {
                if(st > en)
                {
                        swap(st, en);
                }

                for(int i = st+k; i < en; i+=k)
                {
                        if(str[i] == '#')
                        {
                                flag = true;
                                break;
                        }
                }
                if(flag)
                {
                        cout << "NO" << endl;
                }
                else
                {
                        cout << "YES" << endl;
                }
        }

        return 0;
}

B - Urbanization

题意和思路:将n个整数分成两份,一份含n1个数,另一份含n2个数,求所有分法中第一份的平均数和第二份的平均数之和的最大值。现将数组sort一下,比较n1和n2的大小,记小的为n1,大的为n2,将最后n1个数分成一份,接下来n2个数分成一份所求平均数最大。

#include <iostream>
#include <iomanip>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <list> 
#include <stack>
#include <deque>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
#define debug(x) cout << "--------------> " << x << endl

using namespace std;

const int MAXN = 100000 + 7;
const double eps = 1e-8;

using namespace std;

const int MAXN = 100000 + 7;
const double eps = 1e-8;

int main()
{
        int num[MAXN];
        memset(num, 0, sizeof(num));
        int n;
        int a, b;
        cin >> n >> a >> b;
        for(int i = 0; i < n; ++i)
        {
                scanf("%d", &num[i]);
        }
        sort(num, num+n);
        int index = n-a+b;
        if(a > b)
                swap(a, b);
        int cnt = b - a;
        long long va, vb;   //注意这里是long long
        va = vb = 0;

        for(int i = n-1; i > n-a-1; --i)
        {
                va += num[i];
        }
        for(int i = n-a-1; i > n-a-b-1; --i)
        {
                vb += num[i];
        }
        double l, r, mid, x, y;
        l = 0, r = va*1.0;

        x = 1.0*va / a;
        y = 1.0*vb / b;

        printf("%.8f\n", x+y);
        return 0;
}

C - Tennis Championship

题意和思路:n个人比赛,输一次就会被淘汰,两个人能比赛的条件是他们参加比赛的常数只差小于等于1,稳比完赛后最终冠军最大参赛场数。
记num[i]为冠军赢i场比赛最少需要的人数(为保证比赛场数尽可能的多,其实就是确认一下每一轮比赛后有没有轮空的人,有就让轮空的人熟)
则有: f[i] = f[i-1] + f[i-2] //为保证消耗的人最少,知道剩下的人不够为止 斐波那契数列预处理啦~
当然: f[i] = f[i-1] + f[i-1] 也是可以的,就是第i场比赛的选手都进行了i-1场比赛,但相对于上面的情况,输的那一队则是浪费了赢第i-1场比赛的队友之前的比赛所消耗的人数。

#include <iostream>
#include <iomanip>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <deque>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>

#define debug(x) cout << "--------------> " << x << endl

using namespace std;

const int MAXN = 100+1;
const double eps = 1e-8;

long long num[MAXN];

void init()
{
        num[0] = num[1] = 1;
        for(int i = 2; i < MAXN; ++i)
        {
                num[i] = num[i-1] + num[i-2];
        }
}

int main()
{
        init();
        long long n;
        cin >> n;
        int index = 0;
        while(n - num[index] > 0)
        {
                n -= num[index++];
        }
        cout << index << endl;
        return 0;
}

D - Taxes

题意和思路:给一个数n,求将其分成质数的最小份数,且所有质数之和等于n。
这个题,直接用哥德巴赫猜想,如果你不用结论能AC的话你就证明哥德巴赫猜想了~~~
哥德巴赫猜想:对一个大于2的偶数n,一定能分成两个质数之和。
故n=2特判为1,当n为偶数且n不等于2时答案为2,当n为奇数时,若n本身就是质数则答案为1,否则看一下n-2是不是质数,如果是,则答案为2(不能分成1),不是答案则为3。因为n-2不是质数则n-2>2,又n不是质数但n是奇数,故此时n最小从9开始即n>=9,故只要将n分解成n-3和3就行了。n-3是大于2的偶数,故此时答案为3。

#include <iostream>
#include <iomanip>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <deque>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>

#define debug(x) cout << "--------------> " << x << endl

using namespace std;

const int MAXN = 100+1;
const double eps = 1e-8;

bool isPrime(int x)
{
        for(int i = 2; i <= sqrt(x); ++i)
        {
                if(x % i == 0)
                        return false;
        }
        return true;
}

int main()
{
        int n;
        cin >> n;
        if(n == 2)
        {
                cout << 1 << endl;
        }
        else if(n % 2 == 0)
        {
                cout << 2 << endl;
        }
        else
        {
                if(isPrime(n))
                {
                        cout << 1 << endl;
                }
                else
                {
                        if(isPrime(n-2))
                        {
                                cout << 2 << endl;
                        }
                        else
                        {
                                cout << 3 << endl;
                        }
                }
        }
        return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值