设为首页 加入收藏

TOP

Codeforces Round #306 (Div. 2) (ABCE题解)(二)
2015-11-21 00:59:49 来源: 作者: 【 】 浏览:11
Tags:Codeforces Round #306 Div. ABCE 题解
ase to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits.

If a solution exists, you should print it.

Input

The single line of the input contains a non-negative integer n. The representation of number n doesn't contain any leading zeroes and its length doesn't exceed 100 digits.

Output

Print NO (without quotes), if there is no such way to remove some digits from number n.

Otherwise, print YES in the first line and the resulting number after removing digits from number n in the second line. The printed number must be divisible by 8.

If there are multiple possible answers, you may print any of them.

Sample test(s) Input
3454
Output
YES
344
Input
10
Output
YES
0
Input
111111
Output
NO

?

题目大意:给个数字,问删去其中一些数字后能不能被8整除

?

题目分析:打了个小表,找了找规律,首先有8或0的直接可以,其次包含16,24,32,56,64,72,96之一的都可以,再其次,先找一个奇数,它后面为12,36,44,52,76,92之一的都可以,数字长度很小,暴搞

?

?

#include 
  
   
#include 
   
     int const MAX = 105; char s[MAX]; int len; // 0 // 8 // 16 // 24 // 32 // 56 // 64 // 72 // 96 // 112 // 136 // 144 // 152 // 176 // 192 // 312 // 336 bool judge1(int i, char ch1, char ch2) { if(s[i] == ch1) { for(int j = i + 1; j < len; j++) { if(s[j] == ch2) { printf(YES %c%c , ch1, ch2); return true; } } } return false; } bool judge2(char ch, int i, char ch1, char ch2) { for(int j = i + 1; j < len; j++) { if(s[j] == ch1) { for(int k = j + 1; k < len; k ++) { if(s[k] == ch2) { printf(YES %c%c%c , ch, ch1, ch2); return true; } } } } return false; } int main() { scanf(%s, s); len = strlen(s); for(int i = 0; i < len; i++) { if(s[i] == '0') { printf(YES 0 ); return 0; } if(s[i] == '8') { printf(YES 8 ); return 0; } if(judge1(i, '1', '6')) return 0; if(judge1(i, '2', '4')) return 0; if(judge1(i, '3', '2')) return 0; if(judge1(i, '5', '6')) return 0; if(judge1(i, '6', '4')) return 0; if(judge1(i, '7', '2')) return 0; if(judge1(i, '9', '6')) return 0; if((s[i] - '0') % 2 == 1 && judge2(s[i], i, '1', '2')) return 0; if((s[i] - '0') % 2 == 1 && judge2(s[i], i, '3', '6')) return 0; if((s[i] - '0') % 2 == 1 && judge2(s[i], i, '4', '4')) return 0; if((s[i] - '0') % 2 == 1 && judge2(s[i], i, '5', '2')) return 0; if((s[i] - '0') % 2 == 1 && judge2(s[i], i, '7', '6')) return 0; if((s[i] - '0') % 2 == 1 && judge2(s[i], i, '9', '2')) return 0; } printf(NO ); }
   
  

?

?

?

E. Brackets in Implications time limit per test:2 seconds memory limit per test:256 megabytes

Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false.

Implication is written by using character '\', and the arguments and the result of the implication are written as '0' (false) and '1' (true). According to the definition of the implication:

\

\

\

\

When a logical expression contains multiple implications, then when there are no brackets, it will be calculated from left to fight. For example,

\.

When there are brackets, we first calculate the expression in brackets. For example,

\.

For the given logical expression \ determine if it is possible to place there brackets so that the value of a logical expression is false. If it is possible, your task is to find such an arrangement of brackets.

Input

The first line contains integer n (1?≤?n?≤?100?000) — the number of arguments in a logical expression.

The second line contains n numbers a1,?a2,?...,?an (\), which means the values of arguments in the expression in the order they occur.

Output

Print NO (without the quotes), if it is impossible to place brackets in the expression so that its value was equal to 0.

Otherwise, print YES in the first line and the logical expression with the required arrangement of brackets in the second line.

The expression should only contain characters '0', '1', '-' (character with ASCII code 45), '>' (character with ASCII code 62), '(' and ')'. Characters '-' and '>' can occur in an expression only paired like that: (->) and represent implication. The total number of logical arguments (i.e. digits '0' and '1') in the expression must be equal to n. The order in which the digits follow in the expression from left to right must coincide with a1,?a2,?...,?an.

The expression should be correct. More formally, a correct expression is determined as follows:

Expressions 0, 1 (without the quotes) are correct. If v 1, v 2 are correct, then v 1-> v 2 is a correct expression. If v is a correct expression, then ( v) is a correct expression.

The total number of characters in the resulting expression mustn't exceed 106.

If there ar

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ3623:Best Cow Line, Gold(后.. 下一篇C Language Study - 函数指针的使..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: