其他分享
首页 > 其他分享> > Codeforces Round #571 (Div. 2)

Codeforces Round #571 (Div. 2)

作者:互联网

Codeforces Round #571 (Div. 2)

D. Vus the Cossack and Numbers

Description

Vus the Cossack has nn real numbers aiai. It is known that the sum of all numbers is equal to 00. He wants to choose a sequence bb the size of which is nn such that the sum of all numbers is 00and each bibi is either ⌊ai⌋⌊ai⌋ or ⌈ai⌉⌈ai⌉. In other words, bibi equals aiai rounded up or down. It is not necessary to round to the nearest integer.

For example, if a=[4.58413,1.22491,−2.10517,−3.70387]a=[4.58413,1.22491,−2.10517,−3.70387], then bb can be equal, for example, to [4,2,−2,−4][4,2,−2,−4].

Note that if aiai is an integer, then there is no difference between ⌊ai⌋⌊ai⌋ and ⌈ai⌉⌈ai⌉, bibi will always be equal to aiai.

Help Vus the Cossack find such sequence!

Input

The first line contains one integer nn (1≤n≤1051≤n≤105) — the number of numbers.

Each of the next nn lines contains one real number aiai (|ai|<105|ai|<105). It is guaranteed that each aiai has exactly 55 digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to 00.

output

In each of the next nn lines, print one integer bibi. For each ii, |ai−bi|<1|ai−bi|<1 must be met.

If there are multiple answers, print any.

Examples

Input

4
4.58413
1.22491
-2.10517
-3.70387

Output

4
2
-2
-4

正确解法:

先把所有的数都floor,按小的算,最后加起来不等于0的时候,再加一就好了。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <algorithm>
 5 #include <queue>
 6 #include <vector>
 7 #include <set>
 8 #include <map>
 9 typedef long long ll;
10 const int N=100000+100;
11 const int mod=1e9+7;
12 using namespace std;
13 int n;
14 int a[N],b[N];
15 ll sum=0;
16 double x,esp=1e-9;
17 int main()
18 {
19     scanf("%d",&n);
20     for(int i=1;i<=n;i++)
21     {
22         cin>>x;
23         a[i]=floor(x);
24         if(x-a[i]<esp)  b[i]=1;
25         sum+=a[i];
26     }
27     for(int i=1;i<=n;i++)
28         if(sum<0&&!b[i])
29     {
30         a[i]=a[i]+1;
31         sum++;
32     }
33     for(int i=1;i<=n;i++)
34         cout<<a[i]<<endl;
35  
36  
37  
38     return 0;
39 }
View Code

 

C. Vus the Cossack and Strings

Description

Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings aa and bb. It is known that |b|≤|a||b|≤|a|, that is, the length of bb is at most the length of aa.

The Cossack considers every substring of length |b||b| in string aa. Let's call this substring cc. He matches the corresponding characters in bb and cc, after which he counts the number of positions where the two strings are different. We call this function f(b,c)f(b,c).

For example, let b=00110b=00110, and c=11000c=11000. In these strings, the first, second, third and fourth positions are different.

Vus the Cossack counts the number of such substrings cc such that f(b,c)f(b,c) is even.

For example, let a=01100010a=01100010 and b=00110b=00110. aa has four substrings of the length |b||b|: 0110001100, 1100011000, 1000110001, 0001000010.

Since in three substrings, f(b,c)f(b,c) is even, the answer is 33.

Vus can not find the answer for big strings. That is why he is asking you to help him.

Input

The first line contains a binary string aa (1≤|a|≤1061≤|a|≤106) — the first string.

The second line contains a binary string bb (1≤|b|≤|a|1≤|b|≤|a|) — the second string.

output

Print one number — the answer.

Examples

Input

01100010
00110

Output

3

正确解法:

我在想两个字符串该如何匹配呢?

其实有个简单方法就是找规律。找b中1的个数,若字符串c中1的个数与b同奇偶的话,那么就满足条件。

这用到了前缀和。普遍方法异或还不会qaq

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <queue>
 7 #include <vector>
 8 #include <set>
 9 #include <map>
10 typedef long long ll;
11 const int N=1000000+100;
12 const int mod=1e9+7;
13 using namespace std;
14 char a[N],b[N];
15 int sum[N],cnt=0,ans=0;
16 int main()
17 {
18     scanf("%s\n%s",a+1,b+1);
19     int n=strlen(a+1),m=strlen(b+1);
20     //cout<<n<<" "<<m<<endl;
21     for(int i=1;i<=n;i++)
22     {
23         sum[i]=sum[i-1]+a[i]-'0';
24         //cout<<sum[i]<<" ";
25     }
26     for(int i=1;i<=m;i++)
27         cnt+=b[i]-'0';
28     if(cnt%2==0)
29     {
30         for(int i=m;i<=n;i++)
31             if((sum[i]-sum[i-m])%2==0)
32                 ans++;
33     }
34     else
35     {
36         for(int i=m;i<=n;i++)
37             if((sum[i]-sum[i-m])%2==1)
38                 ans++;
39     }
40     cout<<ans<<endl;
41  
42     return 0;
43 }
View Code

 

标签:int,571,Codeforces,ai,00110,Vus,Div,include,Cossack
来源: https://www.cnblogs.com/Kaike/p/11124512.html