csa66

Risk Rolls

Time limit: 1000 ms
Memory limit: 256 MB

 

Alena and Boris are playing Risk today. We'll call an outcome the sum of values on the faces of 111 or more rolled dice. Alena has NNN possible outcomes whilst Boris has MMM. In turns, each one of them will choose their best possible available outcome and play it. If Alena's outcome is strictly greater than Boris's, then Alena wins; otherwise Boris wins. Whenever one of them runs out of outcomes, the game ends.

In how many turns does Alena win? What about Boris?

Standard input

The first line contains two integers NNN and MMM.

The second contains NNN integers, Alena's possible outcomes.

The third line contains MMM integers, Boris's possible outcomes.

Standard output

Print two integers AAA and BBB on the first line of the output; AAA represents the number of turns won by Alena and BBB the number of turns won by Boris.

Constraints and notes

  • 1≤N,M≤101 \leq N, M \leq 101≤N,M≤10
  • 1≤v≤241 \leq v \leq 241≤v≤24, where vvv is a possible outcome value
Input Output Explanation
1 3
24
1 2 3
1 0

In the first turn, Alena will play 242424, which will beat Boris's 333

3 1
2 1 3
24
0 1

This is the first sample with reversed outcomes for Alena and Boris.

2 2
10 1
5 5
1 1
 
4 3
3 4 5 24
9 9 9
1 2

In the first turn Alena will beat Boris because she will play 242424.

3 3
8 9 10
10 8 8
1 2

In the first turn they will play 101010 against 101010 and Boris will win. On the second turn they will play 999 versus 888 and Alena will win. The third turn is also won by Boris.

直接做就好了,排序,注意有个strictly就是大于

#include <bits/stdc++.h>
using namespace std;
int a[],b[];
int cmp(int a,int b)
{
return a>b;
}
int main()
{
int n,m;
cin>>n>>m;
int mi=min(n,m);
for(int i=;i<n;i++)
cin>>a[i];
for(int i=;i<m;i++)
cin>>b[i];
sort(a,a+n,cmp);
sort(b,b+n,cmp);
int af=,bf=;
for(int i=;i<mi;i++)
if(a[i]>b[i])af++;
else bf++;
cout<<af<<" "<<bf;
return ;
}

Processing Discounts

Time limit: 1000 ms
Memory limit: 256 MB

 

You've just placed an order of XXX USD on an online shopping website. The website has NNN special discounts: if you make a purchase of at least AiA_iA​i​​ USD, you get back BiB_iB​i​​ USD. It may be advantageous to increase your order bill just so you would be eligible of certain discount offers.

What's the minimum amount of USD that you have to pay in the end, after processing the discounts?

Standard input

The first line contains two integers, NNN and XXX.

The next NNN lines contain a pair of integers, AiA_iA​i​​ and BiB_iB​i​​.

Standard output

Print the answer on the first line.

Constraints and notes

  • 1≤N≤1051 \leq N \leq 10^51≤N≤10​5​​
  • 1≤X,Ai,Bi≤1061\leq X, A_i, B_i \leq 10^61≤X,A​i​​,B​i​​≤10​6​​
  • The online shopping website will never become in debt to you, i.e. the discount offers are chosen in such a way that you'd never reach a negative amount of payment.
Input Output Explanation
3 99
50 5
75 10
100 5
80

We're eligible for the first two discount offers, so we get 5+10=155 + 10 = 155+10=15 USD back. This means that in the end we'll pay 99−15=8499 - 15 = 8499−15=84 USD.

If we increase our order up to 100100100 USD, we'll be eligible for the third offer as well and we'll pay only 100−5−10−5=80100 - 5 - 10 - 5 = 80100−5−10−5=80 USD.

5 50
10 1
20 2
30 3
30 3
100 10
41

We're eligible for all the discount offers besides the last one. If we were to increase our payment in order to get the last offer, we would end up with 100−10−3−3−2−1=81100 - 10 - 3 - 3 - 2 - 1 = 81100−10−3−3−2−1=81 USD.

It's better to only consider the first 333, we end up spending 50−3−3−2−1=4150 - 3 - 3 - 2 - 1 = 4150−3−3−2−1=41 USD.

1 10
100 95
5
 
1 200
100 95
105
 
 
B就是一个优惠券的问题,排下序,找到付款最小值就行了
#include<bits/stdc++.h>
using namespace std;
int n,x;
const int N=1e5+;
pair<int,int> a[N];
int main()
{
scanf("%d%d",&n,&x);
for(int i=; i<n; i++)
scanf("%d%d",&a[i].first,&a[i].second);
sort(a,a+n);
int sum=x, s=;
for(int i=; i<n; i++)
s+=a[i].second,sum=min(sum,max(a[i].first,x)-s);
printf("%d\n",sum);
return ;
}

Counting Quacks

Time limit: 1000 ms
Memory limit: 256 MB

 

There are NN ducks on a lake. Every duck ii quacks periodically, once every X_iX​i​​ moments of time; i.e. it quacks for the first time at the X_i^{\text{th}}X​i​th​​ moment of time, it quacks for the second time at the {2 * X_i}^{\text{th}}2∗X​i​​​th​​ moment and so on...

Alex is sitting near this lake and he asks himself:

  • What's the maximum number of quacks i'll hear at the same moment of time?
  • How many times i'll hear this many quacks throughout my staying at the lake?

Alex isn't feeling so contemplative today, so he's leaving the lake after TT moments of time. After he leaves he won't be able to hear any more quacks.

Standard input

The first line contains two integers, NN and TT.

The next line contains NN integers representing XX.

Standard output

The first line contains two integers separated by space, as described in the statement.

Constraints and notes

  • 1 \leq N \leq 10^51≤N≤10​5​​
  • 1 \leq T \leq 10^61≤T≤10​6​​
  • 1 \leq X_i \leq 10^61≤X​i​​≤10​6​​ for each 1 \leq i \leq N1≤i≤N
  • Alex comes at the lake at the moment of time 11.
Input Output
3 6
2 2 3
3 1
3 5
2 2 3
2 2
6 10
1 2 3 4 5 6
4 1

C当时太脑残了,没想到正确的做法,甚至想着去维护这些数,但是T不大啊,直接用埃筛的思想处理下就行了,复杂度O(T+TogT)

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+;
int n,T,a[N],M[N];
int main()
{
scanf("%d%d",&n,&T);
for(int i=,x; i<n; i++)
scanf("%d",&x),++M[x];
for(int i=; i<=T; i++)
{
if(!M[i])continue;
for(int j=i; j<=T; j+=i)a[j]+=M[i];
}
int ans=,cnt=;
for(int i=; i<=T; i++)
if(a[i]>ans)ans=a[i],cnt=;
else if(a[i]==ans) cnt++;
printf("%d %d\n",ans,cnt);
return ;
}

Flipping Matrix

Time limit: 1000 ms
Memory limit: 256 MB

 

You are given a binary matrix AA of size N \times NN×N. You are allowed to perform the following two operations:

  • Take two rows and swap them. If we want to swap rows xx and yy, we'll encode this operation as R x y.
  • Take two columns and swap them. If we want to swap columns xx and yy, we'll encode this operation as C x y.

Is it possible to obtain only values of 11 on the main diagonal of AA by performing a sequence of at most NN operations? If so, print the required operations.

Standard input

The first line contains NN.

The next NN lines contain NN binary values separated by spaces, representing AA.

Standard output

If there is no solution, print -1−1.

Otherwise, print every operation on a separated line.

Constraints and notes

  • 2 \leq N \leq 10^32≤N≤10​3​​
  • 0 \leq A_{i, j} \leq 10≤A​i,j​​≤1 for every 1 \leq i, j \leq N1≤i,j≤N
Input Output
3
0 0 1
0 1 0
1 0 0
C 1 3
4
1 1 0 0
0 1 0 1
1 1 0 0
0 0 0 1
-1
5
0 1 0 0 1
0 0 1 0 0
0 1 0 0 0
0 0 1 1 0
1 0 0 0 0
R 1 5
C 2 3

是个特判题,虽说可以交换行和列,但是其实交换哪个都一样,dfs遍历看看有没有机会得到对角线全是1,需要优秀的暴力,因为n还是很大的

#include<bits/stdc++.h>
using namespace std;
const int N=;
int a[N][N],F[N],n,y[N];
int dfs(int x)
{
for(int i=; i<=n; i++)
if(a[x][i]&&!y[i])
{
y[i]=;
if(!F[i]||dfs(F[i]))
{
F[i]=x;
return ;
}
}
return ;
}
int la()
{
for(int i=; i<=n; i++)
{
memset(y,,sizeof y);
if(!dfs(i))return ;
}
return ;
}
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
scanf("%d",a[i]+j);
if(!la())puts("-1");
else
{
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
if(F[j]==i)
{
if(j!=i)swap(F[j],F[i]),printf("C %d %d\n",i,j);
break;
}
}
return ;
}

csa Round #66 (Div. 2 only)的更多相关文章

  1. csa Round #73 (Div. 2 only)

    Three Equal Time limit: 1000 msMemory limit: 256 MB   You are given an array AA of NN integers betwe ...

  2. BestCoder Round #66 (div.2)B GTW likes gt

    思路:一个O(n)O(n)的做法.我们发现b_1,b_2,...,b_xb​1​​,b​2​​,...,b​x​​都加11就相当于b_{x+1},b_{x+2},...,b_nb​x+1​​,b​x+ ...

  3. BestCoder Round #66 (div.2)

    构造 1002 GTW likes gt 题意:中文题面 分析:照着题解做的,我们可以倒着做,记一下最大值,如果遇到了修改操作,就把最大值减1,然后判断一下这个人会不会被消灭掉,然后再更新一下最大值. ...

  4. HDU5597/BestCoder Round #66 (div.2) GTW likes function 打表欧拉函数

    GTW likes function      Memory Limit: 131072/131072 K (Java/Others) 问题描述 现在给出下列两个定义: f(x)=f_{0}(x)=\ ...

  5. HDU5596/BestCoder Round #66 (div.2) 二分BIT/贪心

    GTW likes gt    Memory Limit: 131072/131072 K (Java/Others) 问题描述 从前,有nn只萌萌的GT,他们分成了两组在一起玩游戏.他们会排列成一排 ...

  6. HDU 5596/BestCoder Round #66 (div.2) GTW likes math 签到

    GTW likes math  Memory Limit: 131072/131072 K (Java/Others) 问题描述 某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学<从自主 ...

  7. BestCoder Round #66 (div.2) hdu5592

    GTW likes math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  8. CSA Round #53 (Div. 2 only) Histogram Partition(模拟)

    传送门 题意 给出一个数组A,你有一个数组B(一开始全为0),询问多少次操作后B转化为A 一次操作:选择一段区间,加上某个正整数 分析 构建一个栈, 输入一个数,若当前栈空或栈顶元素比输入小,则加入栈 ...

  9. CSA Round #50 (Div. 2 only) Min Swaps(模拟)

    传送门 题意 给出一个排列,定义\(value为\sum_{i=1}^{n-1}abs(f[i+1]-f[i])\) \(swap(a[i],a[j])(i≠j)为一次交换\),询问最少的交换次数使得 ...

随机推荐

  1. java核心技术 - 17个重要的知识点

    1.Java中没有多继承,而是用接口来代替多继承 2.运行一个已经编译的程序时,Java解释器总是从指定类的main方法中的代码开始执行,因此,执行代码中必须有一个main函数. 3.Java是典型的 ...

  2. 【TensorFlow入门完全指南】神经网络篇·MLP多层感知机

    前面的不做过多解释了. 这里定义了两个占位符,各位也知道,在训练时,feed_dict会填充它们. 定义相关网络. 这里是权值矩阵和偏差. 这里是实例化了网络,定义了优化器和损失,和上一篇一样. 最后 ...

  3. Mongodb之failed to create service entry worker thread

    Mongodb "failed to create service entry worker thread" 错误. 系统:CentOS release 6.8 mongod.lo ...

  4. CF Gym 100187M Heaviside Function(二分)

    题意:给你一个函数和一些系数,给你一堆询问,求函数值. 根据s的符号,分成两组讨论,函数值与比x小的系数数量有关,二分输出答案. #include<cstdio> #include< ...

  5. 香港城市大学:全球首创3D打印微型机器人技术 有望作治疗癌症用途

    香港城市大学(香港城大)的研究团队开发出了全球首创以磁力控制的3D打印微型机器人,该微型机器人技术能做到在生物体内精准运载细胞到指定的位置.新研发的微型机器人有望应用在治疗癌症的靶向治疗,并为细胞层面 ...

  6. 【转】iOS学习笔记(十五)——数据库操作(SQLite)

    SQLite (http://www.sqlite.org/docs.html) 是一个轻量级的关系数据库.SQLite最初的设计目标是用于嵌入式系统,它占用资源非常少,在嵌入式设备中,只需要几百K的 ...

  7. hdparm - 获取/设置硬盘参数

    总览 hdparm [ -a [扇区数] ] [ -A [0|1] ] [ -c [芯片组模式] ] [ -C ] [ -d [0|1] ] [ -f ] [ -g ] [ -i ] [ -k [0| ...

  8. 不安装oracle客户端如何使用plsql连接数据库

    不安装oracle客户端如何使用plsql连接数据库 1. 准备工作 1.1下载plsqldev破解版软件 我这里使用plsqldev715版本 1.2下载instantclient-basic-wi ...

  9. cron job 里面,如何让脚本半分钟运行一次?

    cron job 里面,如何让脚本半分钟运行一次? cron本身实现不了.但可以借助于sleep命令实现. 解决方法: 两个脚本 一个正常,一个增加sleep 30 crontab设置同时启动 在有的 ...

  10. python爬虫用到的一些东西

    原装requests >>> import requests >>> response = requests.get('http://www.baidu.com') ...