题目链接: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. Which dispatch method would be used in Swift?-Existential Container

    In this example: protocol MyProtocol { func testFuncA() } extension MyProtocol { func testFuncA() { ...

  2. nodejs的学习

    nodejs 就是使用js来编写服务端的程序.它的特性是(单线程   速度快   耗内存多  异步   事件驱动) ( 一些技术的解决方案:默认情况下是 1.不支持多核,可以使用cluster 进行解 ...

  3. c++ 模板template

    1.函数模板的声明 声明形式 template<typename 数据类型参数标识符> <返回类型><函数名>(参数表) {     函数体 } 注: templa ...

  4. Getting start with dbus in systemd (02) - How to create a private dbus-daemon

    Getting start with dbus in systemd (02) 创建一个私有的dbus-daemon (session) 环境 这里我们会有两个app: app1(client),ap ...

  5. MFC定时器的使用

    巧妙地使用定时器能达到意想不到的效果,写界面的时候能实现渐变,也能帮助多线程控制等我们知道,在VC的MFC中,已经为我们封装好了很多全面和强大的函数集,所以在MFC编程时,巧妙地调用MFC函数库可以为 ...

  6. [Python3网络爬虫开发实战] 1.9.2-Scrapyd的安装

    Scrapyd是一个用于部署和运行Scrapy项目的工具,有了它,你可以将写好的Scrapy项目上传到云主机并通过API来控制它的运行. 既然是Scrapy项目部署,基本上都使用Linux主机,所以本 ...

  7. LINUX:Contos7.0 / 7.2 LAMP+R 下载安装Php篇

    文章来源:http://www.cnblogs.com/hello-tl/p/7569071.html 更新时间:2017-09-21 16:03 简介 LAMP+R指Linux+Apache+Mys ...

  8. django-1创建项目创建app设置setting、urls、templates、views等

    1. python -m django --version 查看版本 1.11.4 在需要创建项目的目录下执行: 2. django-admin startproject myblog => 创 ...

  9. random,json,pickle,hashlib,shutil,hmac,shelve 模块

    一,复习 ''' 项目开发规范 ATM -- bin: 可执行文件 # run.py import os import sys BASE_DIR = os.path.dirname(os.path.d ...

  10. socket scoketserver

    import socket sk = socket.socket() # 创建了一个socket对象 # sk.setsockopt(socket.SOL_SOCKET,socket.SO_REUSE ...