Codeforces Round #306 (Div. 2) A B C
题目链接: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的更多相关文章
- 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight
题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...
- DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad
题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...
- 水题 Codeforces Round #306 (Div. 2) A. Two Substrings
题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...
- 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 ...
- 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 ...
- 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/ ...
- 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 ...
- 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 ...
- Codeforces Round #306 (Div. 2) 550A Two Substrings
链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...
随机推荐
- Vue beaforeCreate时获取data中的数据
异步获取即:通过 $this.$nextTick或者settimeout,这连dom都可以拿出来 beforeCreate() { this.$nextTick(function() { con ...
- swiper 3D 覆盖流的使用方法
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...
- 全国绿色计算大赛 模拟赛第二阶段 (Python)
第1关气温预测 def dailyTemps(temp_list): result = [] for ca in range(0, len(temp_list)-1): for i in range( ...
- Python模块 shelve xml configparser hashlib
常用模块1. shelve 一个字典对象模块 自动序列化2.xml 是一个文件格式 写配置文件或数据交换 <a name="hades">123</a>3. ...
- 2 SQL 查询基础
2 查询基础 2-1 SELECT语句基础 通过SELECT语句查询并选取必要数据的过程称为匹配查询或查询(query). 子句是SQL语句的组成要素,是以SELECT或者FROM等作为起始的短语. ...
- js 技巧 (二)
//最小化,最大化,关闭 <object id=min classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"> & ...
- django+uwsgi+nginx部署(非常详细)
django+uwsgi+nginx部署 1.介绍: 在网上看了很多教程,但自己部署了很久都没有成功,这篇博文记录自己所踩过得坑. 2.环境: Ubuntu 16.04.1 LTS (GNU/Linu ...
- Python Pandas库的学习(一)
今天我们来学习一下Pandas库,前面我们讲了Numpy库的学习 接下来我们学习一下比较重要的库Pandas库,这个库比Numpy库还重要 Pandas库是在Numpy库上进行了封装,相当于高级Num ...
- 多.h项目出现的问题:使用了预编译头依然出现error LNK2005:***obj已在***obj中定义与c++ error C2011: “xxx”:“class”类型重定义解决办法
使用了预编译头依然出现error LNK2005:***obj已在***obj中定义 造成该问题的可能性比较多,本人将在今后遇到时添加进来,今天先放出本人遇到的一种情况. 多重包含含有变量定义的.h文 ...
- Python面试快问快答,理论要的就是速度与精准,Python面试题No2
今天的面试题 第1题:python2和python3的range(100)的区别 range()函数的含义 range函数是一个用来创建算数级数序列的通用函数,返回一个[start, start + ...