CodeForces 146A Lucky Ticket

Lucky Ticket

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 146A

Description

Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket‘s number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky.

Input

The first line contains an even integer n(2 ≤ n ≤ 50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n — the ticket number. The number may contain leading zeros.

Output

On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).

Sample Input

Input

247

Output

NO

Input

44738

Output

NO

Input

44774

Output

YES

Hint

In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).

In the second sample the ticket number is not the lucky number.

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     char a[105];
 8     int i,j,n;
 9     while(scanf("%d",&n)!=EOF)
10     {
11         int flg=1,s1=0,s2=0;
12         scanf("%s",a);
13         for(i=0;i<n;i++)
14         {
15             if(i<n/2)
16                 s1=s1+a[i]-‘0‘;
17             else
18                 s2=s2+a[i]-‘0‘;
19             if(a[i]==‘4‘ || a[i]==‘7‘)
20             {
21                 flg=1;
22             }
23             else
24             {
25                 flg=0;
26                 break;
27             }
28         }
29         //printf("%d %d\n",s1,s2);
30         if(s1!=s2)
31             flg=0;
32         if(flg)
33             printf("YES\n");
34         else
35             printf("NO\n");
36     }
37     return 0;
38 }

时间: 2024-10-29 19:06:43

CodeForces 146A Lucky Ticket的相关文章

CodeForces E. Lucky Array 幸运数列

CodeForces    E. Lucky Array  幸运数列 Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are n

Codeforces 121A Lucky Sum

Lucky Sum Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 121A64-bit integer IO format: %I64d      Java class name: (Any) Petya loves lucky numbers. Everybody knows that lucky numbers are positive int

Codeforces 109C Lucky Tree 组合计数+dfs

题目链接:点击打开链接 题意: 给定n个点的树,有边权. 定义lucky number:数字只有4或7组成 对于一个三元组(i, j, k) 若path(i,j) 路径上的数字存在lucky number && path(i,k) 路径上的数字存在lucky number 则三元组合法. 问有多少个合法的三元组. ( (i,j,k) != (i,k,j) ) 用全集-补集.dfs出每个只由 非lucky number 构成的联通块 的点数 x . 然后方法数就是 x*(x-1)*(x-2)

codeforces 630C - Lucky Numbers 递推思路

630C - Lucky Numbers 题目大意: 给定数字位数,且这个数字只能由7和8组成,问有多少种组合的可能性 思路: 假设为1位,只有7和8:两位的时候,除了77,78,87,88之外还哇哦加上前面只有7和8的情况,一共是6位.所以递推式不难写出dp[i]=pow(2,i)+dp[i-1]; 代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; ll ans[56]; void init ()

codeforces 110E Lucky Tree

传送门:https://codeforces.com/contest/110/problem/E 题意:给你一颗树,节点与节点之间的边有一个边权,定义只由4和7组成的数字是幸运数字,现在要你求一共有多少条路径,使得节点u->v之间至少存在一条边为幸运数字 题解:树形dp+容斥,我们要找有多少条路径上至少存在一条幸运边,那么我们就可以找到所有的不含幸运路径的边然后用所有路径和减去不含幸运路径的边即可 1,每次输入边权的时候处理边权是否为幸运数字,如果是,那么为1,否则为0 2,dfs处理,如果边权

codeforces #303A Lucky Permutation Triple 构造

题目大意:给定n,要求构造三个0~n?1的排列A,B,C,使得对于任意i(i∈[0,n?1])满足Ai+Bi≡Ci(mod n) 首先我们来考虑n是奇数的情况.以n=7为例 A 0 1 2 3 4 5 6 B 6 4 2 0 5 3 1 C 6 5 4 3 2 1 0 看出来怎么构造的了么? 没错,排列A每次+1,排列B每次?2,排列C每次?1 由于n是奇数,这样可以保证A,B,C三个排列都不重复 那么n是偶数的时候怎么构造呢?n是偶数的时候无解! 为什么呢?我们可以计算一下三个排列的和! 显然

Codeforces 1096G. Lucky Tickets【生成函数】

LINK 题目大意 很简单自己看 思路 考虑生成函数(为啥tags里面有一个dp啊) 显然,每一个指数上是否有系数是由数集中是否有这个数决定的 有的话就是1没有就是0 然后求出这个生成函数的\(\frac{n}{2}\)次方 把每一项的系数全部平方加起来..没了 #include<bits/stdc++.h> using namespace std; typedef vector<int> Poly; const int N = 3e6 + 10; const int Mod =

ural 1217. Unlucky Tickets

1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each time in the bus, getting a ticket with a 6-digit number, they try to sum up the first half of digits and the last half of digits. If these two sums ar

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive