Codeforces Round #379 (Div. 2) A B C D 水 二分 模拟
1 second
256 megabytes
standard input
standard output
Anton likes to play chess, and so does his friend Danik.
Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this.
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of games played.
The second line contains a string s, consisting of n uppercase English letters 'A' and 'D' — the outcome of each of the games. The i-th character of the string is equal to 'A' if the Anton won the i-th game and 'D' if Danik won the i-th game.
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes).
6
ADAAAA
Anton
7
DDDAADA
Danik
6
DADADA
Friendship
In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
题意:水
题解:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#define __int64 ll
using namespace std;
int n;
char a;
int s=,b=;
int main()
{
scanf("%d",&n);
s=;
b=;
getchar();
for(int i=; i<=n; i++)
{
scanf("%c",&a);
if(a=='A')
s++;
else
b++;
}
if(s>b)
cout<<"Anton"<<endl;
if(s<b)
cout<<"Danik"<<endl;
if(s==b)
cout<<"Friendship"<<endl;
return ;
}
1 second
256 megabytes
standard input
standard output
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
5 1 3 4
800
1 1 1 1
256
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.
题意:水
题解:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#define ll __int64
using namespace std;
ll a,b,c,d;
int main()
{
scanf("%I64d %I64d %I64d %I64d",&a,&b,&c,&d);
ll minx=;
minx=min(a,min(c,d));
ll ling=;
ll exm=max(ling,a-minx);
ll minx1=min(exm,b);
cout<<minx*+minx1*<<endl;
return ;
}
4 seconds
256 megabytes
standard input
standard output
Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare n potions.
Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two types that can faster the process of preparing potions.
- Spells of this type speed up the preparation time of one potion. There are m spells of this type, the i-th of them costs bi manapoints and changes the preparation time of each potion to ai instead of x.
- Spells of this type immediately prepare some number of potions. There are k such spells, the i-th of them costs di manapoints and instantly create ci potions.
Anton can use no more than one spell of the first type and no more than one spell of the second type, and the total number of manapoints spent should not exceed s. Consider that all spells are used instantly and right before Anton starts to prepare potions.
Anton wants to get to the next level as fast as possible, so he is interested in the minimum number of time he needs to spent in order to prepare at least n potions.
The first line of the input contains three integers n, m, k (1 ≤ n ≤ 2·109, 1 ≤ m, k ≤ 2·105) — the number of potions, Anton has to make, the number of spells of the first type and the number of spells of the second type.
The second line of the input contains two integers x and s (2 ≤ x ≤ 2·109, 1 ≤ s ≤ 2·109) — the initial number of seconds required to prepare one potion and the number of manapoints Anton can use.
The third line contains m integers ai (1 ≤ ai < x) — the number of seconds it will take to prepare one potion if the i-th spell of the first type is used.
The fourth line contains m integers bi (1 ≤ bi ≤ 2·109) — the number of manapoints to use the i-th spell of the first type.
There are k integers ci (1 ≤ ci ≤ n) in the fifth line — the number of potions that will be immediately created if the i-th spell of the second type is used. It's guaranteed that ci are not decreasing, i.e. ci ≤ cj if i < j.
The sixth line contains k integers di (1 ≤ di ≤ 2·109) — the number of manapoints required to use the i-th spell of the second type. It's guaranteed that di are not decreasing, i.e. di ≤ dj if i < j.
Print one integer — the minimum time one has to spent in order to prepare n potions.
20 3 2
10 99
2 4 3
20 10 40
4 15
10 80
20
20 3 2
10 99
2 4 3
200 100 400
4 15
100 800
200
In the first sample, the optimum answer is to use the second spell of the first type that costs 10 manapoints. Thus, the preparation time of each potion changes to 4 seconds. Also, Anton should use the second spell of the second type to instantly prepare 15 potions spending 80 manapoints. The total number of manapoints used is 10 + 80 = 90, and the preparation time is 4·5 = 20 seconds (15 potions were prepared instantly, and the remaining 5 will take 4 seconds each).
In the second sample, Anton can't use any of the spells, so he just prepares 20 potions, spending 10 seconds on each of them and the answer is 20·10 = 200.
题意:
题解:枚举第一种魔法 二分第二种魔法 取最优解
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#define ll __int64
using namespace std;
ll n,m,k;
ll x,s;
struct node
{
ll w;
ll cost;
} N[],M[],zha[];
bool check(int xx,ll cc)
{
if(M[xx].cost<=cc)
return true;
else
return false;
}
int main()
{
scanf("%I64d %I64d %I64d",&n,&m,&k);
scanf("%I64d %I64d",&x,&s);
N[].w=x;
N[].cost=;
M[].w=;
M[].cost=;
for(int i=; i<=m; i++)
scanf("%I64d",&N[i].w);
for(int i=; i<=m; i++)
scanf("%I64d",&N[i].cost);
for(int i=; i<=k; i++)
scanf("%I64d",&M[i].w);
for(int i=; i<=k; i++)
scanf("%I64d",&M[i].cost);
ll ans=n*x;
for(int i=; i<=m; i++)
{
if((s-N[i].cost)>=){
int l=,r=k,mid;
int aaa=;
while(l<=r)
{
mid=(l+r)/;
if(check(mid,s-N[i].cost))
{
aaa=mid;
l=mid+;
}
else
{
r=mid-;
}
}
if(M[aaa].w>=n)
ans=;
else
ans=min(ans,N[i].w*(n-M[aaa].w));
}
}
printf("%I64d\n",ans);
return ;
}
4 seconds
256 megabytes
standard input
standard output
Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead.
The first task he faced is to check whether the king is in check. Anton doesn't know how to implement this so he asks you to help.
Consider that an infinite chess board contains one white king and the number of black pieces. There are only rooks, bishops and queens, as the other pieces are not supported yet. The white king is said to be in check if at least one black piece can reach the cell with the king in one move.
Help Anton and write the program that for the given position determines whether the white king is in check.
Remainder, on how do chess pieces move:
- Bishop moves any number of cells diagonally, but it can't "leap" over the occupied cells.
- Rook moves any number of cells horizontally or vertically, but it also can't "leap" over the occupied cells.
- Queen is able to move any number of cells horizontally, vertically or diagonally, but it also can't "leap".
The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of black pieces.
The second line contains two integers x0 and y0 ( - 109 ≤ x0, y0 ≤ 109) — coordinates of the white king.
Then follow n lines, each of them contains a character and two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — type of the i-th piece and its position. Character 'B' stands for the bishop, 'R' for the rook and 'Q' for the queen. It's guaranteed that no two pieces occupy the same position.
The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.
2
4 2
R 1 1
B 1 5
YES
2
4 2
R 3 3
B 1 5
NO
Picture for the first sample:
White king is in check, because the black bishop can reach the cell with the white king in one move. The answer is "YES".
Picture for the second sample:
Here bishop can't reach the cell with the white king, because his path is blocked by the rook, and the bishop cant "leap" over it. Rook can't reach the white king, because it can't move diagonally. Hence, the king is not in check and the answer is "NO".
题意:国际象棋中 判断king是否被check
题解:模拟 找的8个方向最近的棋子
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#define ll __int64
using namespace std;
int n;
ll x,y;
ll xx[],yy[];
char a[];
int main()
{
scanf("%d",&n);
scanf("%I64d %I64d",&x,&y);
a[]='#';
for(int i=;i<=n;i++){
getchar();
scanf("%c %I64d %I64d",&a[i],&xx[i],&yy[i]);}
int s1=,s2=,s3=,s4=,s5=,s6=,s7=,s8=;
ll minx=1e10;
for(int i=;i<=n;i++)
{
if(xx[i]==x&&yy[i]>y){
if(minx>yy[i]){
s1=i;
minx=yy[i];
}
}
}
minx=-1e10;
for(int i=;i<=n;i++)
{
if(xx[i]==x&&yy[i]<y){
if(minx<yy[i]){
s2=i;
minx=yy[i];
}
}
}
minx=1e10;
for(int i=;i<=n;i++)
{
if(xx[i]>x&&yy[i]==y){
if(minx>xx[i]){
s3=i;
minx=xx[i];
}
}
}
minx=-1e10;
for(int i=;i<=n;i++)
{
if(xx[i]<x&&yy[i]==y){
if(minx<xx[i]){
s4=i;
minx=xx[i];
}
}
}
minx=1e10;
for(int i=;i<=n;i++)
{
if(xx[i]>x&&yy[i]>y&&(xx[i]-yy[i])==(x-y)){
if(minx>yy[i]){
s5=i;
minx=yy[i];
}
}
}
minx=-1e10;
for(int i=;i<=n;i++)
{
if(xx[i]<x&&yy[i]<y&&(xx[i]-yy[i])==(x-y)){
if(minx<yy[i]){
s6=i;
minx=yy[i];
}
}
}
minx=-1e10;
for(int i=;i<=n;i++)
{
if(xx[i]>x&&yy[i]<y&&(xx[i]+yy[i])==(x+y)){
if(minx<yy[i]){
s7=i;
minx=yy[i];
}
}
}
minx=1e10;
for(int i=;i<=n;i++)
{
if(xx[i]<x&&yy[i]>y&&(xx[i]+yy[i])==(x+y)){
if(minx>yy[i]){
s8=i;
minx=yy[i];
}
}
}
if((s1!=&&a[s1]!='B')||(s2!=&&a[s2]!='B')||(s3!=&&a[s3]!='B')
||(s4!=&&a[s4]!='B')||(s5!=&&a[s5]!='R')
||(s6!=&&a[s6]!='R')||(s7!=&&a[s7]!='R')||(s8!=&&a[s8]!='R'))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return ;
}
Codeforces Round #379 (Div. 2) A B C D 水 二分 模拟的更多相关文章
- Codeforces Round #379 (Div. 2) D. Anton and Chess 水题
D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play ...
- Codeforces Round #379 (Div. 2) B. Anton and Digits 水题
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...
- Codeforces Round #379 (Div. 2) A. Anton and Danik 水题
A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play ...
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions —— 二分
题目链接:http://codeforces.com/contest/734/problem/C C. Anton and Making Potions time limit per test 4 s ...
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions 二分
C. Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集
A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...
- Codeforces Round #379 (Div. 2) Analyses By Team:Red & Black
A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lu ...
- Codeforces Round #379 (Div. 2) E. Anton and Tree 缩点 直径
E. Anton and Tree 题目连接: http://codeforces.com/contest/734/problem/E Description Anton is growing a t ...
随机推荐
- PHP的后期静态绑定
self 是个孝子 不管后来 谁是它的领导(调用它) 谁生了它 它就听谁的 子类调用父类的方法 self 的生存空间是父类 不管是不是子类调用 我生在哪 我就在哪个类里面找属性/方法 static ...
- Socket Receive 避免 Blocking
我们知道 Socket Blocking 属性默认true . 表明Socket 处于同步调用 , Connect , 或 Send , Receive 需等待动作 完成才能继续执行. 有一种应用场景 ...
- open nms安装教程
而在正式的任务,我被要求在Windows平台上部署开源网络管理系统.虽然工作的任务,我得到了一些问题,对此我无法在网上寻找解决的问题,我用的命中和试验方法得到了解决.然后我想就这些问题及其解决办法写. ...
- 使用GridVIew显示Gantt(甘特图),动态增减列
说明:本例是做了工厂的排机报表 一.根据查询日期初始化GridView列 private void IniGridView(DateTime p_DateS,DateTime p_DateE) { / ...
- js函数自动执行的一点理解
//声明一个匿名函数并赋值给一个变量 var a = function(){ console.log("executing..."); } //匿名函数调用 a(); 相信上面这段 ...
- Linux学习 :字符设备框架
一.系统功能框架: U-boot : 启动内核 linux kernel: 启动应用 应用: open,read,write 都是通过C库实现,汇编就相当于swi val,引发中断,通过系统调用接口在 ...
- linux 内核学习之八 进程调度过程分析
一 关于进程的补充 进程调度的时机 中断处理过程(包括时钟中断.I/O中断.系统调用和异常)中,直接调用schedule(),或者返回用户态时根据need_resched标记调用schedule() ...
- 破解Outlook数据文件密码/PST访问密码
不少人会经常用outlook,邮件多的时候可能不定期导出一个PST文件,为安全起见,给PST文件设置访问密码,可是时间长了,难免忘记,怎么办呢?不用担心,你自己就可以解决,无论是Outlook97.O ...
- a primary example for Functional programming in javascript
background In pursuit of a real-world application, let’s say we need an e-commerce web applicationfo ...
- 如何在静态博客hexo中只显示摘要信息
默认情况下hexo博客(如本站)的首页显示的是完整的文章 – 而文章比较长的时候这无疑会带来诸多不遍. 那怎么样才能只显示个摘要呢? 方法说白了,其实很简单 – 只要加入一个<!-- more ...