HDU 5734 Acperience ( 数学公式推导、一元二次方程 )
题意 : 给出 n 维向量 W、要你构造一个 n 维向量 B = ( b1、b2、b3 ..... ) ( bi ∈ { +1, -1 } ) 、然后求出对于一个常数 α > 0 使得 || W - αB ||^2 尽量小
分析 :
将 || W - αB || ^ 2 进行化简、如下
未知数是 α
不难看出这是一个一元二次方程 Ax^2 + Bx + C
而根据实际的贪心选择
当 wi > 0 时、有 bi < 0
当 wi < 0 时、有 bi > 0
那么上述方程的 A、B、C 都可以确定并求出且 A > 0
那么根据公式法、此方程有最小值 (4AC - B^2) / (4A)
直接求就行了
- #include<bits/stdc++.h>
- #define LL long long
- #define ULL unsigned long long
- #define scl(i) scanf("%lld", &i)
- #define scll(i, j) scanf("%lld %lld", &i, &j)
- #define sclll(i, j, k) scanf("%lld %lld %lld", &i, &j, &k)
- #define scllll(i, j, k, l) scanf("%lld %lld %lld %lld", &i, &j, &k, &l)
- #define scs(i) scanf("%s", i)
- #define sci(i) scanf("%d", &i)
- #define scd(i) scanf("%lf", &i)
- #define scIl(i) scanf("%I64d", &i)
- #define scii(i, j) scanf("%d %d", &i, &j)
- #define scdd(i, j) scanf("%lf %lf", &i, &j)
- #define scIll(i, j) scanf("%I64d %I64d", &i, &j)
- #define sciii(i, j, k) scanf("%d %d %d", &i, &j, &k)
- #define scddd(i, j, k) scanf("%lf %lf %lf", &i, &j, &k)
- #define scIlll(i, j, k) scanf("%I64d %I64d %I64d", &i, &j, &k)
- #define sciiii(i, j, k, l) scanf("%d %d %d %d", &i, &j, &k, &l)
- #define scdddd(i, j, k, l) scanf("%lf %lf %lf %lf", &i, &j, &k, &l)
- #define scIllll(i, j, k, l) scanf("%I64d %I64d %I64d %I64d", &i, &j, &k, &l)
- #define lson l, m, rt<<1
- #define rson m+1, r, rt<<1|1
- #define lowbit(i) (i & (-i))
- #define mem(i, j) memset(i, j, sizeof(i))
- #define fir first
- #define sec second
- #define VI vector<int>
- #define ins(i) insert(i)
- #define pb(i) push_back(i)
- #define pii pair<int, int>
- #define VL vector<long long>
- #define mk(i, j) make_pair(i, j)
- #define all(i) i.begin(), i.end()
- #define pll pair<long long, long long>
- #define _TIME 0
- #define _INPUT 0
- #define _OUTPUT 0
- clock_t START, END;
- void __stTIME();
- void __enTIME();
- void __IOPUT();
- using namespace std;
- ;
- LL w[maxn], b[maxn];
- int n;
- int main(void){__stTIME();__IOPUT();
- printf("%d", b);
- int nCase;
- sci(nCase);
- while(nCase--){
- sci(n);
- ; i<=n; i++){
- scl(w[i]);
- ) b[i] = 1LL;
- else b[i] = - 1LL;
- }
- LL C = ;
- ; i<=n; i++)
- C += (w[i] * w[i]);
- LL B = ;
- ; i<=n; i++)
- B += (w[i] * b[i]);
- B *= (- 2LL);
- LL A = ;
- ; i<=n; i++)
- A += (b[i] * b[i]);
- LL p = ( * A * C - B * B);
- LL q = * A;
- LL GCD = __gcd(p, q);
- p /= GCD;
- q /= GCD;
- printf("%lld/%lld\n", p, q);
- }
- __enTIME();;}
- void __stTIME()
- {
- #if _TIME
- START = clock();
- #endif
- }
- void __enTIME()
- {
- #if _TIME
- END = clock();
- cerr<<"execute time = "<<(double)(END-START)/CLOCKS_PER_SEC<<endl;
- #endif
- }
- void __IOPUT()
- {
- #if _INPUT
- freopen("in.txt", "r", stdin);
- #endif
- #if _OUTPUT
- freopen("out.txt", "w", stdout);
- #endif
- }
HDU 5734 Acperience ( 数学公式推导、一元二次方程 )的更多相关文章
- HDU 5734 Acperience(数学推导)
Problem Description Deep neural networks (DNN) have shown significant improvements in several applic ...
- HDU 5734 Acperience(返虚入浑)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5734 Acperience (公式推导) 2016杭电多校联合第二场
题目:传送门. #include <iostream> #include <algorithm> #include <cstdio> #include <cs ...
- HDU 5734 Acperience (推导)
Acperience 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5734 Description Deep neural networks (DN ...
- hdu 5734 Acperience 水题
Acperience 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5734 Description Deep neural networks (DN ...
- HDU 5734 Acperience
Acperience Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu 5734 Acperience(2016多校第二场)
Acperience Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDU 2092 (将表达式变成一元二次方程形式)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2092 整数解 Time Limit: 1000/1000 MS (Java/Others) Me ...
- Python数学运算的一个小算法(求一元二次方程的实根)
请定义一个函数quadratic(a, b, c),接收3个参数,返回一元二次方程:ax² + bx + c = 0的两个解. #!/usr/bin/env python # -*- coding: ...
随机推荐
- vscode+php+xdebug won't stop at breakpoint 断点不起作用
not stopping on breakpoints breakpoint not working 原因: 1) php.ini xdebug 端口不配置的情况下,默认是 9000,如果vscode ...
- php中连接tcp服务的三种方式
首先需要现有一个 tcp 服务,我们使用 php中的 socket 系列函数实现 <?php //创建socket套接字 $socket = socket_create(AF_INET, SOC ...
- Python面向对象中的继承、多态和封装
Python面向对象中的继承.多态和封装 一.面向对象的三大特性 封装:把很多数据封装到⼀个对象中,把固定功能的代码封装到⼀个代码块, 函数,对象, 打包成模块. 这都属于封装思想. 继承:⼦类可以⾃ ...
- 基于DNS(Consul)高可用
DNS 推荐从Bind-DLZ入手,资料多可控制度更好(查询DNS记录SQL可定制)据说性能差 Bind-DLZhttps://www.cnblogs.com/saneri/p/8178065.htm ...
- 【第一季】CH07_FPGA_RunLED创建VIVADO工程实验
[第一季]CH07_FPGA_RunLED创建VIVADO工程实验 7.1 硬件图片 先来熟悉一下开发板的硬件:LED部分及按钮部分 7.2 硬件原理图 PIN脚定义(讲解以MIZ702讲解,MIZ7 ...
- 第十一章 ZYNQ-MIZ702 DDR3 PS读写操作方案
本编文章的目的主要用简明的方法在纯PS里对DDR3进行读写. 本文所使用的开发板是Miz702 PC 开发环境版本:Vivado 2015.4 Xilinx SDK 2015.4 11.0本章难度 ...
- 监控 Kubernetes 集群应用
Prometheus的数据指标是通过一个公开的 HTTP(S) 数据接口获取到的,我们不需要单独安装监控的 agent,只需要暴露一个 metrics 接口,Prometheus 就会定期去拉取数据: ...
- GAN——ModeCollapse
GAN——ModeCollapse 2017年05月21日 13:54:31 LiuSpark 阅读数 6821更多 分类专栏: 机器学习 版权声明:本文为博主原创文章,遵循CC 4.0 BY-S ...
- poj 1753高斯
和前面的开关问题差不多,就是要理解一下我们方程等号的右端代表的含义是什么.我们建立的方程是想让对位的位置变或者不变,然后生成增广矩阵的时候要多注意一点. ac代码: #include #include ...
- java读取串口-mfz-rxtx-2.2-20081207-win-x86
1.下载jar包 RXTXcomm.jar 2.实现代码 package main; import java.awt.*; import java.awt.event.*; import java.i ...