hdu-5734 Acperience(數學)

題目鏈接:

Acperience

Time Limit: 4000/2000 MS (Java/Others)

? Memory Limit: 65536/65536 K (Java/Others)


Problem Description
Deep neural networks (DNN) have shown significant improvements in several application domains including computer vision and speech recognition. In computer vision, a particular type of DNN, known as Convolutional Neural Networks (CNN), have demonstrated state-of-the-art results in object recognition and detection.

Convolutional neural networks show reliable results on object recognition and detection that are useful in real world applications. Concurrent to the recent progress in recognition, interesting advancements have been happening in virtual reality (VR by Oculus), augmented reality (AR by HoloLens), and smart wearable devices. Putting these two pieces together, we argue that it is the right time to equip smart portable devices with the power of state-of-the-art recognition systems. However, CNN-based recognition systems need large amounts of memory and computational power. While they perform well on expensive, GPU-based machines, they are often unsuitable for smaller devices like cell phones and embedded electronics.

In order to simplify the networks, Professor Zhang tries to introduce simple, efficient, and accurate approximations to CNNs by binarizing the weights. Professor Zhang needs your help.

More specifically, you are given a weighted vector?W=(w1,w2,...,wn). Professor Zhang would like to find a binary vector?B=(b1,b2,...,bn)?(bi{+1,?1})?and a scaling factor?α0?in such a manner that?W?αB2?is minimum.

Note that???denotes the Euclidean norm (i.e.?X=x21+?+x2n???????????√, where?X=(x1,x2,...,xn)).

?

Input
There are multiple test cases. The first line of input contains an integer?T, indicating the number of test cases. For each test case:

The first line contains an integers?n?(1n100000)?-- the length of the vector. The next line contains?n?integers:?w1,w2,...,wn?(?10000wi10000).

?

Output
For each test case, output the minimum value of?W?αB2?as an irreducible fraction "p/q" where?p,?q?are integers,?q>0.

?

Sample Input
3
4
1 2 3 4
4
2 2 2 2
5
5 6 2 3 4

?

Sample Output
5/1
0/1
10/1
題意:
問∑(w[i]+x[i]*a)^2最小是多少?x[i]=1或-1;a>0;
思路:
∑(w[i]+x[i]*a)^2=∑w[i]^2+n*a^2+2*a*∑x[i]w[i];
∑w[i]^2是常數,現在變成了一個一元二次函數,找出它的最小值;
根據二次函數的的性質,∑x[i]w[i]盡量大,所以就很簡單了;
AC代碼:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>using namespace std;#define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));typedef  long long LL;template<class T> void read(T&num) {char CH; bool F=false;for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {if(!p) { puts("0"); return; }while(p) stk[++ tp] = p%10, p/=10;while(tp) putchar(stk[tp--] + '0');putchar('\n');
}const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=500+10;
const double eps=1e-6;int a[N],n;
LL sum=0,ans=0;LL gcd(LL x,LL y){if(y==0)return x;return gcd(y,x%y);}
int main()
{int t;read(t);while(t--){read(n);sum=0,ans=0;For(i,1,n){read(a[i]);sum=sum+(LL)a[i]*a[i];if(a[i]<0)ans=ans-a[i];else ans=ans+a[i];}LL x=(LL)n;LL g=gcd(x*sum-ans*ans,x);cout<<(x*sum-ans*ans)/g<<"/"<<x/g<<endl;}return 0;
}

  

轉載于:https://www.cnblogs.com/zhangchengc919/p/5692885.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/372610.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/372610.shtml
英文地址,請注明出處:http://en.pswp.cn/news/372610.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Ninject依賴注入(一)

Ninject學習筆記&#xff08;一&#xff09; Ninject學習筆記&#xff08;一&#xff09;理解依賴注入DI概念什么是DI&#xff1f;DI是如何工作的&#xff1f;什么是DI容器使用Ninject如何使用NinjectNinject對象生命周期暫時范圍單例范圍線程范圍請求范圍自定義范圍Ninject模塊…

我如何向團隊解釋依賴注入

最近&#xff0c;我們公司開始開發基于Java的新Web應用程序&#xff0c;經過一些評估過程&#xff0c;我們決定使用Spring。 但是許多團隊成員并不了解Spring和Dependency Injection的原理。 因此&#xff0c;我被要求給出一個速成班&#xff0c;介紹什么是Spring上的依賴注入和…

可以添加自定義的Select控件

1.控件dom <select name"WebSiteTarget" id"WebSiteTarget" class"w1" onchange"editable2(this);"><option value"-1">請選擇城市</option><option>福州</option><option>廈門</op…

innodb_io_capacity =innodb_lru_scan_depth*inoodb_buffer_pool_instances。與 checkpoint

innodb_lru_scan_depth:每個緩沖池刷臟頁的能力 innodb_io_capacity: iops inoodb_buffer_pool_instances8 :緩沖池的個數 .關系&#xff1a; innodb_io_capacity > innodb_lru_scan_depth * inoodb_buffer_pool_instances 轉載于:https://www.cnblogs.com/zengkefu/…

Java中的責任鏈模式

當應有幾個處理器來執行某項操作并為這些處理器定義特定順序時&#xff0c;就需要采用責任鏈設計模式。 在運行時處理器順序的可變性也很重要。模式的UML表示如下&#xff1a; 處理程序定義處理器對象的一般結構。 這里的“ HandleRequest”是抽象處理器方法。 處理程序還具有自…

php的excel源碼下載,PHPExcel-5 - 源碼下載|Windows編程|其他小程序|源代碼 - 源碼中國...

文件名大小更新時間PHPExcel02019-05-11PHPExcel\.gitattributes702019-01-02PHPExcel\.gitignore1082019-01-02PHPExcel\.travis.yml5122019-01-02PHPExcel\16329.xlsx510662019-05-11PHPExcel\19093.xlsx511932019-05-11PHPExcel\43877.xlsx530952019-05-11PHPExcel\62045.xl…

使用Visual Studio Code開發Asp.Net Core WebApi學習筆記(六)-- 依賴注入

本篇將介紹Asp.Net Core中一個非常重要的特性&#xff1a;依賴注入&#xff0c;并展示其簡單用法。 第一部分、概念介紹 Dependency Injection&#xff1a;又稱依賴注入&#xff0c;簡稱DI。在以前的開發方式中&#xff0c;層與層之間、類與類之間都是通過new一個對方的實例進行…

基于JAX-WS的webService開發實例

最近因為工作原因接觸到webService&#xff0c;所以記錄下開發中碰到的問題&#xff0c;方便自己以后復習&#xff0c;順便發揚一下開源精神。剛剛接觸webServie如果有什么錯誤歡迎大家指正。 本地環境&#xff1a;myEclipse10.6 tomcat7 JDK7 jaxws-ri-2.2.10 第一步&#xff…

完整的WebApplication JSF EJB JPA JAAS –第2部分

視圖–創建和JSF設置 本教程是第1部分的繼續。 讓我們創建一個新的Dynamic Web Project 。 如下圖所示創建它&#xff1a; 注意&#xff1a;在某些時候&#xff0c;Eclipse會詢問您是否要添加JSF功能&#xff08;自動完成&#xff09;&#xff0c;然后啟用它。 就像下面的屏幕…

lempel ziv matlab,基于Python的LempelZiv算法的熵估計

此函數允許估計時間序列的熵。它基于Lempel-Ziv壓縮算法。對于長度為n的時間序列&#xff0c;熵估計為&#xff1a;E(1/n和L_i)^-1 ln(n)式中&#xff0c;L逯i是從位置i開始的最短子串的長度&#xff0c;該子串之前沒有從位置1出現到i-1。當n接近無窮大時&#xff0c;估計的熵收…

Android使用繪圖Path總結

Path作為Android中一種相對復雜的繪圖方式&#xff0c;官方文檔中的有些解釋并不是很好理解&#xff0c;這里作一個相對全面一些的總結&#xff0c;供日后查看&#xff0c;也分享給大家&#xff0c;共同進步。 1.基本繪圖方法 addArc(RectF oval, float startAngle, float swee…

2017.3.23下午

下午通過對OSPF基本原理進一步的學習&#xff0c;對上午學習的內容進行了復習。 轉載于:https://www.cnblogs.com/bgd140206206/p/6606192.html

編寫Eclipse插件教程–第1部分

Eclipse是三個最受歡迎的Java開發IDE之一。 其成功的原因之一是其可擴展性。 對于任何知道該怎么做并且已經做到的人來說&#xff0c;編寫eclipse插件都可以非常輕松快捷。 不幸的是&#xff0c;第一次在Eclipse中進行操作可能會非常耗時且令人沮喪。 Eclipse框架非常龐大&…

簡單Window下 Android Studio的安裝

&#xff08;1&#xff09;首先安裝JDK 下載JDK 本人覺得官方網站下JDK比較慢&#xff0c;可以直接百度JDK&#xff0c;&#xff08;如果是64位 百度搜索記得64位&#xff09; 類似于這樣的下載 安裝可以看下教程&#xff0c;包括環境變量的配置 如何安裝JDK &#xff08;2&…

日期處理一之NSLalendar的使用

一、日期和時間模式 日期和時間格式由日期和時間模式字符串組成&#xff0c;在日期和時間模式字符串中未加引號的A到‘Z’和a到‘z’被解釋為模式字母&#xff0c;用來表示日期或時間。字符串元素&#xff0c;文本可以使用單引號&#xff08;‘’&#xff09;引起來使用。定義以…

java的使用Pair要導入什么包,第三方jar包的使用

被導入的外部類所在源文件通常要打包成jar包&#xff0c;java中的jar文件裝的是 .class 文件。它是一種壓縮格式和zip兼容&#xff0c;被稱為jar包。JDK提供的許多類&#xff0c;也是以jar包的形式提供的。在用的時候呢&#xff0c;你的文件里有很多個類&#xff0c;把這些類和…

十大最受歡迎的新Eclipse插件

Eclipse Marketplace仍然是發現有趣且相關的Eclipse插件的地方。 通過Eclipse Marketplace客戶端&#xff0c;每月成功安裝100,000多個基于Eclipse的產品。 我們提供了過去30天 以來所有時間最受歡迎的插件列表。 我認為看看過去12個月中最受歡迎的新插件會很有趣。 以下列出了…

在桌面顯示我電腦

打開Windows PowerShell&#xff08;一個像是命令提示符的東西[藍底白字]&#xff0c;但不是命令提示符&#xff09;&#xff0c;在Windows PowerShell內輸入cmd回車&#xff0c;當返回如下信息&#xff1a; Microsoft Windows [版本 6.2.9200](c) 2012 Microsoft Corporation。…

《Java技術》第二次作業計科1501趙健宇

&#xff08;一&#xff09;學習總結 1.使用Eclipse關聯jdk源代碼,查看String類的equals&#xff08;&#xff09;方法 equals&#xff08;&#xff09;方法截圖 “”比較的是地址。equals方法他同樣使用號進行內存地址的比較。但是equals方法重寫如果號比較不相等&#xff0c;…

注射php,UPDATE注射(mysqlphp)的兩個模式

一.測試環境&#xff1a;OS:Windowsxpsp2php:php4.3.10(mysql4.1.9apache1.3.33二.測試數據庫結構&#xff1a;-----start-----數據庫:test----------------------------------------------------------------表的結構userinfo--CREATETABLEuserinfo(groudidvarchar(12)NOTNULL…