题目链接:http://codeforces.com/contest/550

A

暴力一发。

代码:

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <string.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm> using namespace std; const int MAXN =100010; char s[MAXN];
int pos1[MAXN];
int pos2[MAXN]; int main()
{
while (cin>>s)
{
int ok1 = 0,ok2 = 0;
int tmp = 0;
int len = strlen(s);
int num1 = 0,num2 = 0; for(int i = 0;i < len - 1;i++)
{
if (s[i] == 'A' && s[i+1]=='B')
{
ok1 = 1;
pos1[num1++] = i;
}
if (s[i] == 'B' && s[i+1]=='A')
{
ok2 = 1;
pos2[num2++] = i;
}
}
int ok=0;
if (ok1 == 1 && ok2 == 1)
{
for(int i=0;i < num1;i++)
{
if(ok) break;
for(int j=0;j < num2;j++)
{
if (abs(pos1[i] - pos2[j]) != 1)
{
ok=1;
break;
}
}
}
}
if (ok) puts("YES");
else puts("NO");
}
return 0;
}

B 再暴力一发

#include <math.h>
#include <limits.h>
#include <complex>
#include <string>
#include <functional>
#include <iterator>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <ctime>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <assert.h> using namespace std; int n, l, r, X, a[100];
int ans; void rec(int x, int sum, int mn, int mx, int cnt)
{
if (x == n)
{
if ((cnt >= 2) && (sum >= l) && (sum <= r) && (mx - mn >= X)) ans++;
return;
}
rec(x + 1, sum, mn, mx, cnt);
rec(x + 1, sum + a[x], min(mn, a[x]), max(mx, a[x]), cnt + 1);
} int main() { while(~scanf("%d%d%d%d", &n, &l, &r, &X))
{
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
rec(0, 0, 1e9, -1e9, 0);
printf("%d\n", ans);
}
}

C 再再暴力一发

代码:

#include <math.h>
#include <limits.h>
#include <complex>
#include <string>
#include <functional>
#include <iterator>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <ctime>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <assert.h> using namespace std; char s [1010]; void solve()
{
int len = strlen(s);
for(int i=0;i<len;i++)
{
if((s[i] - 48) % 8 == 0)
{
puts("YES");
printf("%c\n",s[i]);
return;
}
}
for(int i=0;i<len;i++)
{
for(int j=i+1;j<len;j++)
{
int num = s[i] - 48;
num = num *10 + s[j]-48;
if (num % 8 == 0)
{
puts("YES");
printf("%d\n",num);
return;
}
}
}
for(int i=0;i<len;i++)
{
if (s[i] != '0')
for(int j=i+1;j<len;j++)
for(int k=j+1;k<len;k++)
{
int num = s[i]-48;
num = num*10 + s[j] - 48;
num = num*10 + s[k] - 48;
if (num % 8 == 0)
{
puts("YES");
printf("%d\n",num);
return ;
} } }
puts("NO");
} int main()
{
while (cin>>s)
{
int len = strlen(s);
solve();
}
return 0;
}

Codeforces Round #306 (Div. 2) A B C的更多相关文章

  1. 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

    题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...

  2. DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad

    题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...

  3. 水题 Codeforces Round #306 (Div. 2) A. Two Substrings

    题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...

  4. Codeforces Round #306 (Div. 2) E. Brackets in Implications 构造

    E. Brackets in Implications Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  5. Codeforces Round #306 (Div. 2) D. Regular Bridge 构造

    D. Regular Bridge Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  6. Codeforces Round #306 (Div. 2) C. Divisibility by Eight 暴力

    C. Divisibility by Eight Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  7. Codeforces Round #306 (Div. 2) B. Preparing Olympiad dfs

    B. Preparing Olympiad Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550 ...

  8. Codeforces Round #306 (Div. 2) A. Two Substrings 水题

    A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  9. Codeforces Round #306 (Div. 2) 550A Two Substrings

    链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...

随机推荐

  1. Laravel Homestead的安装和使用(照搬)

    原文:https://blog.csdn.net/woqianduo/article/details/81091154/ 1.简介 1.1.Homestead是什么 Laravel Homestead ...

  2. phphstrom改变项目中文件排列方式

    1.View>Tool Win dows>Project 效果图: 2.File->settings (Ctrl+Alt+S)-> Editor->General-> ...

  3. sqllite相关总结

    一,sqlite 简介 前面写了一篇博文讲如何在 C# 中使用 ADO 访问各种数据库,在移动开发和嵌入式领域也有一个轻量级的开源关系型数据库-sqlite.它的特点是零配置(无需服务器),单磁盘文件 ...

  4. Tomcat:Error parsing HTTP request header Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.

    可能原因一: 在本地tomcat启动正常并且访问正常的项目放在服务器上tomcat报以上错误. 本地tomcat为7.0.68,服务器上为7.0.86 错误原因:服务器tomcat版本过高. 解决办法 ...

  5. xshell连接不了虚拟机处理方法(错误提示:Connection closing...Socket close.Connection closed by foreign host.Disconnected from remote host(localhost) at 08:47:23.)

    一.问题描述:xshell连接不了虚拟机,出现错误提示:Connection closing...Socket close.Connection closed by foreign host.Disc ...

  6. buf.fill()

    buf.fill(value[, offset[, end]][, encoding]) value {String} | {Buffer} | {Number} offset {Number} 默认 ...

  7. FreeRTOS--疑难杂症

    花了3个晚上,把这个章节看完,受益匪浅. 最有用的应该是与中断相关的错误,优先排查中断优先级设置. 堆栈溢出检查,可能用到,一般先把堆栈设置的足够大,只要没有溢出就是好事,溢出了,掌握了栈溢出钩子函数 ...

  8. Java恶搞!强制关闭电脑上的程序进程!

    效果 最近写代码经常和各种进程打交道,发现了一个很有意思的黑科技. 我直接说有什么用吧,可以设置每隔多少时间检查某个程序是否在使用,如果在用,就强制关闭.比如,有的sb舍友晚上就是不睡觉,一边打游戏一 ...

  9. Leetcode 147.对链表进行排序

    对链表进行插入排序 对链表进行插入排序. 插入排序算法: 插入排序是迭代的,每次只移动一个元素,直到所有元素可以形成一个有序的输出列表. 每次迭代中,插入排序只从输入数据中移除一个待排序的元素,找到它 ...

  10. 九度oj 题目1077:最大序列和

    题目1077:最大序列和 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6435 解决:1931 题目描述: 给出一个整数序列S,其中有N个数,定义其中一个非空连续子序列T中所有数的和为T ...