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的前面几个还是比较水的. 所以看到这道题我果断觉 ...
随机推荐
- group by 和 聚合函数的使用
有这样一个表数据: 学生姓名,学生手机号,上课日期,上课科目 科目分: 语文.数学.英语.计算机 要求统计一个这样子的结果: 学生姓名,学生手机号,第一次上课日期,迄今一共上了多少节课,上的最多的科目 ...
- div 可视化区域弹窗居中
效果: css: .div_alt { position: fixed; border-radius: 5px; top: 50%; left: 50%; width: auto; min-width ...
- iOS中声音采集与播放的实现(使用AudioQueue)
都说iOS最恶心的部分是流媒体,其中恶心的恶心之处更在即时语音. 所以我们先不谈即时语音,研究一下,iOS中声音采集与播放的实现. 要在iOS设备上实现录音和播放功能,苹果提供了简单的做法,那就是利用 ...
- [模板] Treap
插入x 删除x 查询排名为x的数 查询x的排名 求x的前驱.后继 //Stay foolish,stay hungry,stay young,stay simple #include<iostr ...
- Ztree节点前加上两个自定义按钮
前言: 在我的权限管理模块遇到了给某些角色加权限的问题,这时就需要实现将每个模块做成树,在每个节点前加上预览和编辑的按钮,这样可以根据数据库的某个字段给每个角色赋权限. 必须必须吐槽的是,这部分的功能 ...
- 使用requests+BeaBeautiful Soup爬取妹子图图片
1. Requests:让 HTTP 服务人类 Requests 继承了urllib2的所有特性.Requests支持HTTP连接保持和连接池,支持使用cookie保持会话,支持文件上传,支持自动确定 ...
- ELK6.3.2+filebeat部署过程
ELK安装部署 elk作为公司的日志收集检索的方案的首选,是必要的工具,下面介绍一下elk的安装部署方法,以及一些报错的解决方法:(使用的是ubuntu16.04,jdk使用1.8,ELK的版本为6. ...
- Python Pandas库的学习(三)
今天我们来继续讲解Python中的Pandas库的基本用法 那么我们如何使用pandas对数据进行排序操作呢? food.sort_values("Sodium_(mg)",inp ...
- IIS 注册.NET Framework 4.0 命令
cmd执行以下命令 32位Windows:C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i 64位Windows:C ...
- 【转】Java IO流 overview
Java流操作有关的类或接口: Java流类图结构: 流的概念和作用 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称或抽象.即数据在两设备间的传输称为流,流的本质是数据传输,根据数据传输 ...