Codeforces Round #306 (Div. 2) A B C
2015-06-06 11:11
405 查看
A - Two Substrings 题意:字符串中是否有BA 和AB且字母不重叠
暴力for过去找即可
B - Preparing Olympiad 题意:n道题任取几道,使难度总和在 【l, r】,最大难度的题-最小的 >= x,的情况数量
枚举所以得题目情况,依次判断即可
C - Divisibility by Eight
题意:100位的数,可以移除一些位数,但是相对位子不能变,问有没有存在情况使移除(或者不移除)后的被8整除。
首先考虑到,被8整除的数,后三位一定能被8整除,那么暴力枚举后三位就行了,O(n^3)。
暴力for过去找即可
#include <map> #include <set> #include <queue> #include <stack> #include <vector> #include <string> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <algorithm> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 #define ls rt << 1 #define rs rt << 1 | 1 #define pi acos(-1.0) #define eps 1e-8 #define asd puts("sdfsdfsdfsdfsdfsdf"); typedef long long ll; typedef __int64 LL; const int inf = 0x3f3f3f3f; const int N = 100010; char a ; int main() { while( ~scanf("%s", a) ) { int len = strlen( a ); if( len < 4 ) { puts("NO"); continue; } bool OK = 0; for( int i = 0; i < len-1; ++i ) { if( a[i] == 'A' && a[i+1] == 'B' ) { for( int j = i+2; j < len-1; ++j ) { if( a[j] == 'B' && a[j+1] == 'A' ) { OK = 1; break; } } break; } } for( int i = 0; i < len-1; ++i ) { if( a[i] == 'B' && a[i+1] == 'A' ) { for( int j = i+2; j < len-1; ++j ) { if( a[j] == 'A' && a[j+1] == 'B' ) { OK = 1; break; } } break; } } if( OK ) puts("YES"); else puts("NO"); } return 0; }
B - Preparing Olympiad 题意:n道题任取几道,使难度总和在 【l, r】,最大难度的题-最小的 >= x,的情况数量
枚举所以得题目情况,依次判断即可
const int N = 20; int a ; int n, l, r, x; int main() { while( ~scanf("%d%d%d%d", &n, &l, &r, &x) ) { for( int i = 0; i < n; ++i ) scanf("%d", &a[i]); int ans = 0; for( int i = 0; i < (1<<n); ++i ) { int L = inf, R = -1; int cnt = 0, tmp = 0; for( int j = 0; j < n; ++j ) { if( i & (1<<j) ) { L = min( L, a[j] ); R = max( R, a[j] ); tmp += a[j]; cnt++; } } if( R-L >= x && cnt >= 2 && tmp <= r && tmp >= l ) ans++; } printf("%d\n", ans); } return 0; }
C - Divisibility by Eight
题意:100位的数,可以移除一些位数,但是相对位子不能变,问有没有存在情况使移除(或者不移除)后的被8整除。
首先考虑到,被8整除的数,后三位一定能被8整除,那么暴力枚举后三位就行了,O(n^3)。
const int N = 105; char a ; int main() { while( ~scanf("%s", a)) { int len = strlen(a); bool OK = 0; int x; for( int i = 0; i < len; ++i ) { if( a[i] == '0' || a[i] == '8' ) { x = a[i] - '0'; OK = 1; break; } for( int j = i+1; j < len; ++j ) { x = 0; x = x * 10 + a[i] - '0'; x = x * 10 + a[j] - '0'; if( x % 8 == 0 ) { OK = 1; break; } for( int k = j+1; k < len; ++k ) { x = 0; x = a[i] - '0'; x = x * 10 + a[j] - '0'; x = x * 10 + a[k] - '0'; if( x % 8 == 0 ) { OK = 1; break; } } if( OK ) break; } if( OK ) break; } if( OK ) printf("YES\n%d\n", x); else puts("NO"); } return 0; }
相关文章推荐
- CAP原理
- TAT,我的LCT转双旋了
- Leetcode[12-13] Roman to Integer & Integer to Roman(Java)
- arduino小车马达原理
- hdu 1849 (尼姆博弈)
- Shell awk 求标准差
- 【转】 linux内核移植和网卡驱动(二)
- 理解String不可变
- CSS Padding(填充)
- pom.xml第一行报错
- UIImage基础语法
- 软件概要设计与详细设计的区别
- 将CorelDRAW文件转成PSD分层文件详解
- 【转】 linux内核移植和驱动添加(三)
- JavaScript中String.match()方法的使用详解
- DEV C++使用说明
- setRestoreOriginalFrame
- 《机器学习实战》-朴素贝叶斯笔记
- LightOJ1011---Marriage Ceremonies (状压dp)
- surface pro 3系统运行中关闭fn功能键