第六场补题(待续)

UVA 253

当时打比赛的时候把测试数据一块输出了,所以wa,好气

 

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define ll long long
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
int main()
{
    string s;
    while(cin >> s)
    {
        //string c0 = s[0], c1 = s[1], c2 = s[2], c3 = s[3], c4 = s[4], c5 = s[5];
        string s1 = s.substr(0, 1) + s.substr(5, 1);
        string s2 = s.substr(1, 1) + s.substr(4, 1);
        string s3 = s.substr(2, 1) + s.substr(3, 1);
        string S[5];
        S[1] = s.substr(6, 1) + s.substr(11, 1);
        S[2] = s.substr(7, 1) + s.substr(10, 1);
        S[3] = s.substr(8, 1) + s.substr(9, 1);
        //cout<<s1<<' '<<s2<<' '<<s3<<' '<<S[1]<<' '<<S[2]<<' '<<S[3]<<endl;
        bool flag = 0;
        for(int i = 1; i <= 3; i ++)
        {
            int cnt = 0;
//            cout<<S[i]<<endl;
//            cout<<S[i].substr(1, 1)<<endl;
//            cout<<S[i].substr(0, 1)<<endl;
//            cout<<S[i].substr(1, 1) + S[i].substr(0, 1)<<endl;
            if(s1 == S[i] || (s1 == S[i].substr(1, 1) + S[i].substr(0, 1)))
            {
                cnt ++;
                int t1 = 1 + i, t2 = 2 + i;
                if(t1 > 3) t1 -= 3;
                if(t2 > 3) t2 -= 3;
                if(s2 == S[t1] || (s2 == S[t1].substr(1, 1) + S[t1].substr(0, 1)))
                {
                    cnt ++;
                    if(s3 == S[t2] || (s3 == S[t2].substr(1, 1) + S[t2].substr(0, 1)))
                        cnt ++;
                }
                else if(s2 == S[t2] || (s2 == S[t2].substr(1, 1) + S[t2].substr(0, 1)))
                {
                    cnt ++;
                    if(s3 == S[t1] || (s3 == S[t1].substr(1, 1) + S[t1].substr(0, 1)))
                        cnt ++;
                }
            }
            if(cnt == 3)
            {
                flag = 1;
                break;
            }
        }
        if(flag) printf("TRUE\n");
        else printf("FALSE\n");
    }
    return 0;
}

CodeForces - 192A

二分

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int main()
{
    int n;
    bool flag = 0;
    scanf("%d", &n);
    for(int i = 1; i <= sqrt(2 * n); i ++)
    {
        int a = i * (i + 1) / 2;
        int l = i, r = sqrt(2 * n), mid = (l + r) / 2;
        while(l <= r)
        {
            int b = mid * (mid + 1) / 2;
            
            if(a + b < n)
            {
                l = mid + 1;
            }
            else if(a + b > n)
            {
                r = mid - 1;
            }
            else
            {
                flag = 1;
                break;
            }
            mid = (l + r) / 2;
        }
        if(flag) break;
        
    }
    if(flag) printf("YES\n");
    else printf("NO\n");
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值