第一次参加这个比赛
A:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "";
cin >> str;
int m = 0, n = 0, i = 0;
for (i = 0, m = 0, n = 0; i < str.size(); i++)
{
if ((m == 0) && (str.at(i) == 'A'))
{
if (i + 1 < str.size())
{
if (str.at(i + 1) == 'B')
{
i++;
m = 1;
continue;
}
}
}
if ((m != 0)&&(n == 0) && (str.at(i) == 'B'))
{
if (i + 1 < str.size())
{
if (str.at(i + 1) == 'A')
{
i++;
n = 1;
}
}
}
}
if (m && n)
{
cout << "YES";
return 0;
}
for (i = 0, m = 0, n = 0; i < str.size(); i++)
{
if ((m == 0) && (str.at(i) == 'B'))
{
if (i + 1 < str.size())
{
if (str.at(i + 1) == 'A')
{
i++;
m = 1;
continue;
}
}
}
if ((m != 0) && (n == 0) && (str.at(i) == 'A'))
{
if (i + 1 < str.size())
{
if (str.at(i + 1) == 'B')
{
i++;
n = 1;
}
}
}
}
if (m && n)
{
cout << "YES";
return 0;
}
cout << "NO";
return 0;
}
这一题一开始就想到了”ABAXXXAB“这样的测试点,写完代码后感觉自己完成了这个测试点
但是不知道怎么回事,最后发现还是个错的,最后修改了一点点,改对了
if ((m != 0) && (n == 0) && (str.at(i) == 'A'))
主要是这个里面加了一个
(m != 0)
B:
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;
int c[16] = { 0 };
int s[16] = { 0 };
int n = 0, way = 0;
ll l = 0, r = 0, x = 0;
void judge(int s[], int j)
{
int total = 0;
if (s[j - 1] - s[0] < x) return;
for (int i = 0; i < j; i++)
total += s[i];
if (total < l || total > r) return;
way++;
}
void select(int i, int j)//j represent the length of s;
{
if (i == n)
{
judge(s, j);
return;
}
select(i + 1, j);
s[j++] = c[i];
select(i + 1, j);
}
int main()
{
int j = 0;
cin >> n >> l >> r >> x;
for (int i = 0; i <n; i++)
cin >> c[i];//0~n-1
sort(c, c + n);
select(0, j);
cout << way << endl;
}
这一题是赛后做出来的,本来就想到了用二进制进行移位,最后还是没有用
for(int i=0; i<(1<<n); i++){
for(int j=0; j<15; j++){
if( (i>>j)&1 ){
可以这样用
C:暴力求解
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "";
cin >> str;
int num = 0;
for (int i = 0; i < str.size(); i++)
{
if (str.at(i) == '0')
{
cout << "YES" << endl;
cout << "0";
return 0;
}
if (str.at(i) == '8')
{
cout << "YES" << endl;
cout << "8";
return 0;
}
}
for (int i = 0; i < str.size(); i++)
{
for (int j = i + 1; j < str.size(); j++)
{
num = (str.at(i) - '0') * 10 + (str.at(j) - '0');
if (num % 8 == 0)
{
cout << "YES" << endl;
cout << num;
return 0;
}
}
}
for (int i = 0; i < str.size(); i++)
{
for (int j = i + 1; j < str.size(); j++)
{
for (int k = j + 1; k < str.size(); k++)
{
num = (str.at(i) - '0') * 100 + (str.at(j) - '0') * 10 + (str.at(k) - '0');
if (num % 8 == 0)
{
cout << "YES" << endl;
cout << num;
return 0;
}
}
}
}
cout << "NO";
return 0;
}
D:
#include <iostream>
using namespace std;
int main()
{
int k = 0;
int n = 0, m = 0, h = 0;
int v1 = 0, v2 = 0;
cin >> k;
if ((k % 2) == 0)
{
cout << "NO";
return 0;
}
cout << "YES" << endl;
n = 4 * k - 2;
h = 2 * k * k - k;
m = k;
cout << n << " " << h << endl;
for (int i = 1; i < m; i++)
{
v1 = 1;
v2 = i + 1;
cout << v1 << " " << v2 << endl;
}// first vertice
for (int i = 2; i <= m; i++)
{
for (int j = m + 1; j <= 2*m - 1; j++)
{
v1 = i;
v2 = j;
cout << v1 << " " << v2 << endl;
}
}//2~m vertice
for (int i = m + 1; i <= 2*m - 1; i = i + 2)
{
v1 = i;
v2 = i + 1;
cout << v1 << " " << v2 << endl;
}
int app = 2*m - 1;
v1 = 1;
v2 = 1 + app;
cout << v1 << " " << v2 << endl;
for (int i = 1 + app; i < m + app; i++)
{
v1 = 1 + app;
v2 = i + 1;
cout << v1 << " " << v2 << endl;
}
for (int i = 2 + app; i <= m + app; i++)
{
for (int j = m + 1 + app; j <= 2*m - 1 + app; j++)
{
v1 = i;
v2 = j;
cout << v1 << " " << v2 << endl;
}
}
for (int i = m + 1 + app; i <= 2*m - 1 + app; i = i + 2)
{
v1 = i;
v2 = i + 1;
cout << v1 << " " << v2 << endl;
}
}
这一题开始时推导用了好久,得出结论k必需为一个奇数,之后级还好 了
这一题期望看到他人的思路
E:
#include <iostream>
#define maxn 100000 + 10
using namespace std;
int n;
int a[maxn] = { 0 };
int main()
{
int flag = 0;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
if (n == 1){ cout << "YES" << endl; cout << a[0]; return 0; }
if (a[n - 1] != 0){ cout << "NO"; return 0; }
for (int i = 0; i < n - 2; i++) if (a[i] != 1) { flag = 1; break; }
if (flag == 0 && a[n - 2] == 0){ cout << "NO"; return 0; }
cout << "YES" << endl;
cout << "(";
for (int i = 0; i < n-1; i++)
{
if (a[i] == 1)
cout << "1->";
else
cout << "0)->(";
}
cout << "0)" << endl;
return 0;
}
这一题自认为是正确的,不知是不是题意理解有问题,没有过
有许多总结之处:
感觉用时太长了,一题要做半个小时都不止