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;
}
#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;
}