NOIP模拟 Ball - log积化和
题目描述
Alice 与 Bob 在玩游戏。他们一共玩了 t 轮游戏。游戏中,他们分别获得了 n 个和 m 个小球。每个球上有一个分数。每个人的得分都为他所获得所有小球分数的乘积,分数小者获胜。问每轮游戏谁会获胜?请输出每轮游戏的胜者。数据保证不会出现平局,且两个人分数差异大于任意一个人分数的 1% 。
输入格式
第一行为两人玩的轮数 t(1≤t≤10)。
每一轮游戏的输入中:
第一行一个整数 n,代表 Alice 获得球的个数。
第二行为 n 个整数 ai,代表 Alice 每个球的分数。
第三行一个整数 m,代表 Bob 获得球的个数。
第四行为 m 个整数 bi,代表 Bob 每个球的分数。
输出格式
输出共 t 行,每行为该轮胜者的名字“Alice”或“Bob”。
样例数据 1
输入 [复制]
1
3
2 3 4
4
1 3 4 5
输出
Alice
备注
【样例说明】
Alice:2 * 3 * 4 = 24
Bob: 1 * 3 * 4 * 5 = 60
【数据范围】
对于 40% 的数据:n,m,ai,bi≤10;
对于 100% 的数据:1≤n,m≤100000;-10000≤ai,bi≤10000
题目分析
在精度要求不高的情况下,可以将求积用log化为求和a * b = log(a) + log(b)
.
此题迎刃而解。
code
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 100005, S = 45000;
int t, n, m;
double a, b;
typedef long long ll;
//#define endll putchar('\n')
inline int read(){
int i = 0, f = 1; char ch = getchar();
for(; (ch < '0' || ch > '9') && ch != '-'; ch = getchar());
if(ch == '-') f = -1, ch = getchar();
for(; ch >= '0' && ch <= '9'; ch = getchar())
i = (i << 3) + (i << 1) + (ch - '0');
return i * f;
}
inline void wr(ll x){
if(x < 0) x = -x, putchar('-');
if(x > 9) wr(x / 10);
putchar(x % 10 + '0');
}
int main(){
// freopen("ball.in", "r", stdin);
// freopen("ball.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
t = read();
while(t--){
double fn, fm; fn = fm = 1;
a = b = 1;
n = read();
for(int i = 1; i <= n; i++){
double x = 1.0 * read();
if(fn == 0) continue;
if(x == 0){
fn = 0;
continue;
}
if(x < 0) fn *= -1, x = -x;
a = a + log(x);
}
m = read();
for(int i = 1; i <= m; i++){
double x = 1.0 * read();
if(fm == 0) continue;
if(x == 0){
fm = 0;
continue;
}
if(x < 0) fm *= -1, x = -x;
b = b + log(x);
}
// cout << fn * a << " "<< fm * b;
if(fn * a < fm * b) cout << "Alice" << endl;
else cout << "Bob" << endl;
}
return 0;
}
NOIP模拟 Ball - log积化和的更多相关文章
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- 2018.9.22 NOIP模拟赛
*注意:这套题目应版权方要求,不得公示题面. 从这里开始 Problem A 妹子 Problem B 旅程 Problem C 老大 因为业务水平下滑太严重,去和高一考NOIP模拟,sad... P ...
- noip模拟32[好数学啊]
noip模拟32 solutions 真是无语子,又没上100,无奈死了 虽然我每次都觉得题很难,但是还是有好多上100的 战神都200多了,好生气啊啊啊 从题开始变难之后,我的时间分配越来越不均匀, ...
- noip模拟44[我想我以后会碰见计数题就溜走的]
noip模拟44 solutions 这一场抱零的也忒多了,我也只有45pts 据说好像是把几套题里面最难的收拾出来让我们考得 好惨烈啊,这次的考试我只有第一题骗了40pts,其他都抱零了 T1 Em ...
- 11.7 NOIP模拟赛
目录 2018.11.7 NOIP模拟 A 序列sequence(two pointers) B 锁lock(思路) C 正方形square(埃氏筛) 考试代码 B C 2018.11.7 NOIP模 ...
- NOIP模拟赛-2018.11.7
NOIP模拟赛 如果用命令行编译程序可以发现没加头文件之类的错误. 如果用命令行编译程序可以发现没加头文件之类的错误. 如果用命令行编译程序可以发现没加头文件之类的错误. 编译之前另存一份,听说如果敲 ...
- Nescafe #29 NOIP模拟赛
Nescafe #29 NOIP模拟赛 不知道这种题发出来算不算侵权...毕竟有的题在$bz$上是权限题,但是在$vijos$似乎又有原题...如果这算是侵权的话请联系我,我会尽快删除,谢谢~ 今天开 ...
- NOI.AC NOIP模拟赛 第五场 游记
NOI.AC NOIP模拟赛 第五场 游记 count 题目大意: 长度为\(n+1(n\le10^5)\)的序列\(A\),其中的每个数都是不大于\(n\)的正整数,且\(n\)以内每个正整数至少出 ...
- NOI.AC NOIP模拟赛 第六场 游记
NOI.AC NOIP模拟赛 第六场 游记 queen 题目大意: 在一个\(n\times n(n\le10^5)\)的棋盘上,放有\(m(m\le10^5)\)个皇后,其中每一个皇后都可以向上.下 ...
随机推荐
- Tomcat源代码阅读#1:classloader初始化
Bootstrap 通过Tomcat的启动脚本能够看到启动的入口是在Bootstrap,来看下Bootstrap的main方法, /** * Main method and entry point w ...
- LeetCode Algorithm 02_Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...
- 【例题 6-11 UVA-297】Quadtrees
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 发现根本不用存节点信息. 遇到了叶子节点且为黑色,就直接覆盖矩阵就好(因为是并集); [代码] #include <bits/ ...
- java.util.ConcurrentModificationException(如何避免ConcurrentModificationException)
java.util.ConcurrentModificationException is a very common exception when working with java collecti ...
- js进阶 12 jquery事件汇总
js进阶 12 jquery事件汇总 一.常用事件 页面载入事件 ready() 文档就绪事件(当 HTML 文档就绪可用时) 鼠标事件 click() 触发.或将函数绑定到指定元素的 click 事 ...
- mootools常用特性和示例(基础篇1)
网上关于mootools这个库的信息很少. 公司一些老的项目用到了mootools库,因为要维护,所以接触到了mootools. mootools(文档)官网:http://www.chinamoot ...
- POJ 2402 Palindrome Numbers(LA 2889) 回文数
POJ:http://poj.org/problem?id=2402 LA:https://icpcarchive.ecs.baylor.edu/index.php?option=com_online ...
- 转 OC温故:类的三大特性(封装,继承,多态)
原文标题:OC学习篇之---类的三大特性(封装,继承,多态) 我们都知道,面向对象程序设计中的类有三大特性:继承,封装,多态,这个也是介绍类的时候,必须提到的话题,那么今天就来看一下OC中类的三大特性 ...
- AdminLTE的使用(转)
官方文档link1.AdminLTE的必要配置文件<!-- Tell the browser to be responsive to screen width --> <meta c ...
- [Nuxt] Display Vuex Data Differently in Each Page of Nuxt and Vue.js
You often use the same data in different ways across pages. This lesson walks you through setting up ...