contest链接
A. Vus the Cossack and a Contest
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vus the Cossack holds a programming competition, in which ?n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly ?m pens and ?k notebooks.
Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.
Input
The first line contains three integers ?n, ?m, and ?k (1≤?,?,?≤1001≤n,m,k≤100) — the number of participants, the number of pens, and the number of notebooks respectively.
Output
Print "Yes" if it possible to reward all the participants. Otherwise, print "No".
You can print each letter in any case (upper or lower).
当真是签到题啊,但是我没跑测试样例,WA1可还是真实,还好WA不算WA哈哈哈。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll N, M, K;
int main()
{
scanf("%lld%lld%lld", &N, &M ,&K);
M = min(M, K);
printf(N <= M ? "Yes\n" : "No\n");
return 0;
}
C. Vus the Cossack and Strings
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings ?a and ?b. It is known that |?|≤|?||b|≤|a|, that is, the length of ?b is at most the length of ?a.
The Cossack considers every substring of length |?||b| in string ?a. Let's call this substring ?c. He matches the corresponding characters in ?band ?c, after which he counts the number of positions where the two strings are different. We call this function ?(?,?)f(b,c).
For example, let ?=00110b=00110, and ?=11000c=11000. In these strings, the first, second, third and fourth positions are different.
Vus the Cossack counts the number of such substrings ?c such that ?(?,?)f(b,c) is even.
For example, let ?=01100010a=01100010 and ?=00110b=00110. ?a has four substrings of the length |?||b|: 0110001100, 1100011000, 1000110001, 0001000010.
- ?(00110,01100)=2f(00110,01100)=2;
- ?(00110,11000)=4f(00110,11000)=4;
- ?(00110,10001)=4f(00110,10001)=4;
- ?(00110,00010)=1f(00110,00010)=1.
Since in three substrings, ?(?,?)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 ?a (1≤|?|≤1061≤|a|≤106) — the first string.
The second line contains a binary string ?b (1≤|?|≤|?|1≤|b|≤|a|) — the second string.
Output
Print one number — the answer.
果真,还是很艰难的想到的,我发现,一段区间内影响奇偶的只有1的个数,那么假如1的个数是共奇偶的话,岂不是就是意味着他们一定是偶数的,这样子去求一个前缀和就可以了。
时间复杂度:O(N)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define efs 1e-7
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int maxN = 1e6 + 7;
char a[maxN], b[maxN];
int la, lb, pre[maxN], cb = 0;
int main()
{
scanf("%s", a + 1); scanf("%s", b + 1);
la = (int)strlen(a + 1); lb = (int)strlen(b + 1);
for(int i=1; i<=lb; i++) cb += b[i] == '1';
cb &= 1;
for(int i=1; i<=la; i++) pre[i] = ( a[i] == '1' ? pre[i-1] + 1 : pre[i-1] );
int ans = 0;
for(int i=1; i + lb - 1 <= la; i++)
{
ans += ((pre[i + lb - 1] - pre[i - 1]) & 1) == cb;
}
printf("%d\n", ans);
return 0;
}
D. Vus the Cossack and Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vus the Cossack has ?n real numbers ??ai. It is known that the sum of all numbers is equal to 00. He wants to choose a sequence ?b the size of which is ?n such that the sum of all numbers is 00 and each ??bi is either ⌊??⌋⌊ai⌋ or ⌈??⌉⌈ai⌉. In other words, ??bi equals ??ai rounded up or down. It is not necessary to round to the nearest integer.
For example, if ?=[4.58413,1.22491,−2.10517,−3.70387]a=[4.58413,1.22491,−2.10517,−3.70387], then ?b can be equal, for example, to [4,2,−2,−4][4,2,−2,−4].
Note that if ??ai is an integer, then there is no difference between ⌊??⌋⌊ai⌋ and ⌈??⌉⌈ai⌉, ??bi will always be equal to ??ai.
Help Vus the Cossack find such sequence!
Input
The first line contains one integer ?n (1≤?≤1051≤n≤105) — the number of numbers.
Each of the next ?n lines contains one real number ??ai (|??|<105|ai|<105). It is guaranteed that each ??ai 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 ?n lines, print one integer ??bi. For each ?i, |??−??|<1|ai−bi|<1 must be met.
If there are multiple answers, print any.
这道题,我WA了几次,让我明白了一个道理,强制转换是存在着进位的,我们得用floor()函数,用以向下取整。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define efs 1e-7
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int maxN = 1e5 + 7;
int N;
double a[maxN];
ll b[maxN], det = 0, ans[maxN], sum = 0, change;
bool sure[maxN], up[maxN];
int main()
{
scanf("%d", &N);
memset(sure, false, sizeof(sure));
for(int i=1; i<=N; i++)
{
scanf("%lf", &a[i]);
b[i] = floor(a[i]);
if(fabs(a[i] - 1. * b[i]) < efs) { ans[i] = b[i]; sure[i] = true; }
else
{
ans[i] = b[i];
det++;
}
sum += ans[i];
}
change = -sum;
for(int i=1; i<=N; i++)
{
if(!change) break;
if(sure[i]) continue;
ans[i]++;
change--;
}
for(int i=1; i<=N; i++) printf("%lld\n", ans[i]);
return 0;
}