一個簡單的暴力法
重點:將運算式作調整,可得 y = x*k / (x-k)
x : k+1 -> 2*k ,尋找 (x*k) % (x-k) == 0 的狀況
存入堆疊後列出
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
int main(){
int k;
int note[10000][2];
while(scanf("%d",&k)!=EOF){
int total=0;
memset(note,0,sizeof(note));
for(int i=k+1;i<=2*k;i++){
if((i*k)%(i-k)==0){
note[total][0]=i;
note[total][1]=(i*k)/(i-k);
total++;
}
}
printf("%d\n",total);
for(int i=0;i<total;i++)
printf("1/%d = 1/%d + 1/%d\n",k,note[i][1],note[i][0]);
}
return 0;
}
2015年6月30日星期二
2015年6月29日星期一
Setup Ubuntu 14.10 on Asus X205ta
因為X205的架構非常獨特,Linux對其硬體的支援度非常弱(據說kernel4.0之後有所改善,這倒還需要研究一番),目前的進度是將Ubuntu系統塞進32Gb的固態碟中,並設定能自動抓取開機磁區,之後可能還要針對WIFI、音效、快捷鍵和讀卡機等週邊設備進行設定。
1) 用Rufus製作開機磁碟,設定GPT partition scheme for UEFI computer,filesystem為fat32即可,將iso檔燒錄進去,並將bootia32.efi放進boot/efi/EFI底下
2) 進入BIOS,將Secure Boot Control關掉,USB Controller 改成EHCI
3) 重新開機,按Esc進入開機選單,選擇USB開機,安裝系統過程中因為mmcblk0rpmb會不斷有讀寫錯誤訊息,過程會停頓許久,需耐心等待
4) 到選擇安裝模式的畫面時,選擇將硬碟上所有資料清除,全部安裝為Ubuntu,記得選32Gb的那一塊,其他不要動
5) 安裝完成後重開機,請再次使用USB開機,進入Grub畫面,按下c進入指令行,輸入下列命令:
initrd (hd1,gpt2)/boot/initrd-3.16-0-23-generic
boot
P.S. 安裝完系統後,分割區掛載分別為:
- /boot = /dev/mmcblk0p1
- / = /dev/mmcblk0p2
6) 初次進入系統後,在終端機進行bootia32.efi的建置(為了使EFI晶片能辨識硬碟內Ubuntu之開機磁區)
- apt-get install git bison libopts25 libselinux1-dev autogen m4 autoconf help2man libopts25-dev flex libfont-freetype-perl automake autotools-dev libfreetype6-dev texinfo
# from http://www.gnu.org/software/grub/grub-download.html
- git clone git://git.savannah.gnu.org/grub.git
- cd grub
- ./autogen.sh
- ./configure --with-platform=efi --target=i386 --program-prefix=""
- make
- cd grub-core
- ../grub-install -d . --efi-directory /boot/efi/ --target=i386
- cd /boot/efi/EFI
- cp grub/grubia32.efi ubuntu/
目前這樣可以在開機後順利進入Ubuntu系統,至於週邊驅動的問題解決後再附上。
-------------6/30/2015
經資料查找,應該會先更新Kernel,參考連結如下:
http://magiclen.org/ubuntu-kernel-update/
一些硬體設定參考這兩篇:
http://magiclen.org/asus-x205ta-linux-mint-17/
https://wiki.debian.org/InstallingDebianOn/Asus/X205TA
Sound:
http://www.jfwhome.com/2014/03/07/perfect-ubuntu-or-other-linux-on-the-asus-transformer-book-t100/
成功再貼上
-------------7/4/2015-------------
讀卡機和WIFI設定OK,Kernel更新至4.1.0,Battery status恢復正常
聲音還未成功
觸控版手掌偵測未完成
關閉觸控板(加入至.bashrc)
xinput -disable 12
#可用xinput -list查看設備
修復於Compiz桌面下,Alt+Tab切換視窗無效
先安裝Compiz Config Setting Manager
$sudo apt-get install compizconfig- settings- manager
再裝Plugin
$sudo apt-get install compiz-plugin-main
運行ccsm,將static application switcher點選即可
-------------10/21/2015-------------
如果要修復開機時mmcblk0rpmb 的timeout問題
可以試試看這個:
https://linuxnorth.wordpress.com/2014/08/27/t100-timeout-issue-solved/
-------------6/30/2015
經資料查找,應該會先更新Kernel,參考連結如下:
http://magiclen.org/ubuntu-kernel-update/
一些硬體設定參考這兩篇:
http://magiclen.org/asus-x205ta-linux-mint-17/
https://wiki.debian.org/InstallingDebianOn/Asus/X205TA
Sound:
http://www.jfwhome.com/2014/03/07/perfect-ubuntu-or-other-linux-on-the-asus-transformer-book-t100/
成功再貼上
-------------7/4/2015-------------
讀卡機和WIFI設定OK,Kernel更新至4.1.0,Battery status恢復正常
聲音還未成功
觸控版手掌偵測未完成
關閉觸控板(加入至.bashrc)
xinput -disable 12
#可用xinput -list查看設備
修復於Compiz桌面下,Alt+Tab切換視窗無效
先安裝Compiz Config Setting Manager
$sudo apt-get install compizconfig-
再裝Plugin
$sudo apt-get install compiz-plugin-main
運行ccsm,將static application switcher點選即可
-------------10/21/2015-------------
如果要修復開機時mmcblk0rpmb 的timeout問題
可以試試看這個:
https://linuxnorth.wordpress.com/2014/08/27/t100-timeout-issue-solved/
2015年6月23日星期二
Install linux on ASUS X205
website notes here:
DebianOn : https://wiki.debian.org/InstallingDebianOn/Asus/X205TA
Mint 17: http://magiclen.org/asus-x205ta-linux-mint-17/
Ubuntu : https://github.com/lopaka/instructions/blob/master/ubuntu-14.10-install-asus-x205ta.md
http://askubuntu.com/questions/610456/ubuntu-on-asus-eeebookx205-with-all-peripherals
https://help.ubuntu.com/community/EeePC/Fixes
https://wiki.debian.org/InstallingDebianOn/Asus/X205TA
http://ubuntuforums.org/showthread.php?t=2254322
http://brownbro.github.io/blog/2015/01/15/asus-x205ta-with-lubuntu/
DebianOn : https://wiki.debian.org/InstallingDebianOn/Asus/X205TA
Mint 17: http://magiclen.org/asus-x205ta-linux-mint-17/
Ubuntu : https://github.com/lopaka/instructions/blob/master/ubuntu-14.10-install-asus-x205ta.md
http://askubuntu.com/questions/610456/ubuntu-on-asus-eeebookx205-with-all-peripherals
https://help.ubuntu.com/community/EeePC/Fixes
https://wiki.debian.org/InstallingDebianOn/Asus/X205TA
http://ubuntuforums.org/showthread.php?t=2254322
http://brownbro.github.io/blog/2015/01/15/asus-x205ta-with-lubuntu/
[UVa] 11059 - Maximum Product
暴力求解可得
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <sstream>
using namespace std;
int main(){
int N, i, k, kase=0;;
string line;
while(scanf("%d",&N)!=EOF){
kase++;
long long int S[N];
getchar();
//Input S[0]~S[N-1]
getline(cin,line);
i=0,k=0;
long long int x;
stringstream ss(line);
while(ss>>x){
S[i]=x;
i++;
}
int ok=0;
long long int max=0,tmp;
//count in brute-force
for(i=0;i<N;i++){
tmp = 1;
for(int j=i;j<N;j++){
tmp = tmp * S[j];
if(tmp > max) max = tmp;
}
}
cout << "Case #" << kase << ": The maximum product is "
<< max << "." ;
printf("\n\n");
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <sstream>
using namespace std;
int main(){
int N, i, k, kase=0;;
string line;
while(scanf("%d",&N)!=EOF){
kase++;
long long int S[N];
getchar();
//Input S[0]~S[N-1]
getline(cin,line);
i=0,k=0;
long long int x;
stringstream ss(line);
while(ss>>x){
S[i]=x;
i++;
}
int ok=0;
long long int max=0,tmp;
//count in brute-force
for(i=0;i<N;i++){
tmp = 1;
for(int j=i;j<N;j++){
tmp = tmp * S[j];
if(tmp > max) max = tmp;
}
}
cout << "Case #" << kase << ": The maximum product is "
<< max << "." ;
printf("\n\n");
}
return 0;
}
2015年6月20日星期六
[UVa] 725 - Division
以Brute-force去求解
輸入N,求 N = abcde / fghij
而a~j為0~9的數字,互相不重複
每兩個輸出間要空行,而最後以0結束時又不能多空行
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
int N,a,b; // a / b
int main(){
scanf("%d",&N);
while(1){
int ok=0;
if(N==0)break;
else {
for(int k=0;k<100000;k++){
int b1 = k/10000,
b2 = k%10000/1000,
b3 = k%10000%1000/100,
b4 = k%10000%1000%100/10,
b5 = k%10000%1000%100%10;
//printf("%d %d %d %d\n",b1,b2,b3,b4);
if(b1!=b2 && b1!=b3 && b1!=b4 && b1!=b5 && b2!=b3 && b2!=b4 && b2!=b5
&& b3!=b4 && b3!=b5 && b4!=b5){
b = k;
//printf("%d ",b);
a = b*N;
if(a/10000 >=10)break;
else {
int a1 = a/10000,
a2 = a%10000/1000,
a3 = a%10000%1000/100,
a4 = a%10000%1000%100/10,
a5 = a%10000%1000%100%10;
if( a1!=a2 && a1!=a3 && a1!=a4 && a1!=a5
&& a1!=b1 && a1!=b2 && a1!=b3 && a1!=b4 && a1!=b5
&& a2!=a3 && a2!=a4 && a2!=a5
&& a2!=b1 && a2!=b2 && a2!=b3 && a2!=b4 && a2!=b5
&& a3!=a4 && a3!=a5
&& a3!=b1 && a3!=b2 && a3!=b3 && a3!=b4 && a3!=b5
&& a4!=a5 && a4!=b1 && a4!=b2 && a4!=b3 && a4!=b4 && a4!=b5
&& a5!=b1 && a5!=b2 && a5!=b3 && a5!=b4 && a5!=b5
)
{
printf("%05d / %05d = %d\n",a,b,N);
ok=1;
}
}
}
}
if(ok==0)printf("There are no solutions for %d.\n",N);
}
scanf("%d",&N);
if(N==0)break; else puts("");
}
return 0;
}
Ruija Liu 的神奇寫法
將運算式轉為字串
按照大小排序後,直接檢查0~9是否有缺數字
即可作為題目限制的判定
輸入N,求 N = abcde / fghij
而a~j為0~9的數字,互相不重複
每兩個輸出間要空行,而最後以0結束時又不能多空行
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
int N,a,b; // a / b
int main(){
scanf("%d",&N);
while(1){
int ok=0;
if(N==0)break;
else {
for(int k=0;k<100000;k++){
int b1 = k/10000,
b2 = k%10000/1000,
b3 = k%10000%1000/100,
b4 = k%10000%1000%100/10,
b5 = k%10000%1000%100%10;
//printf("%d %d %d %d\n",b1,b2,b3,b4);
if(b1!=b2 && b1!=b3 && b1!=b4 && b1!=b5 && b2!=b3 && b2!=b4 && b2!=b5
&& b3!=b4 && b3!=b5 && b4!=b5){
b = k;
//printf("%d ",b);
a = b*N;
if(a/10000 >=10)break;
else {
int a1 = a/10000,
a2 = a%10000/1000,
a3 = a%10000%1000/100,
a4 = a%10000%1000%100/10,
a5 = a%10000%1000%100%10;
if( a1!=a2 && a1!=a3 && a1!=a4 && a1!=a5
&& a1!=b1 && a1!=b2 && a1!=b3 && a1!=b4 && a1!=b5
&& a2!=a3 && a2!=a4 && a2!=a5
&& a2!=b1 && a2!=b2 && a2!=b3 && a2!=b4 && a2!=b5
&& a3!=a4 && a3!=a5
&& a3!=b1 && a3!=b2 && a3!=b3 && a3!=b4 && a3!=b5
&& a4!=a5 && a4!=b1 && a4!=b2 && a4!=b3 && a4!=b4 && a4!=b5
&& a5!=b1 && a5!=b2 && a5!=b3 && a5!=b4 && a5!=b5
)
{
printf("%05d / %05d = %d\n",a,b,N);
ok=1;
}
}
}
}
if(ok==0)printf("There are no solutions for %d.\n",N);
}
scanf("%d",&N);
if(N==0)break; else puts("");
}
return 0;
}
Ruija Liu 的神奇寫法
將運算式轉為字串
按照大小排序後,直接檢查0~9是否有缺數字
即可作為題目限制的判定
// UVa725 Division
// Rujia Liu
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main() {
int n, kase = 0;
char buf[99];
while(scanf("%d", &n) == 1 && n) {
int cnt = 0;
if(kase++) printf("\n");
for(int fghij = 1234; ; fghij++) {
int abcde = fghij * n;
sprintf(buf, "%05d%05d", abcde, fghij);
if(strlen(buf) > 10) break;
sort(buf, buf+10);
bool ok = true;
for(int i = 0; i < 10; i++)
if(buf[i] != '0' + i) ok = false;
if(ok) {
cnt++;
printf("%05d / %05d = %d\n", abcde, fghij, n);
}
}
if(!cnt) printf("There are no solutions for %d.\n", n);
}
return 0;
}
訂閱:
文章 (Atom)
-
因為先前寫UVa時,檔案名稱有時會花心思改,有時就直接把題目名稱加上.cpp就貼上了 導致現在有不同的格式出現 現在要處理的事情很簡單 1. 去除空白 2. 將底線 ( _ ) 換成dash ( - ) 經過一番查詢,終於發現最簡單的方法 - re...
-
文章出處: http://infbugs.blogspot.tw/2011/12/c_20.html 謝謝沙耶,解答了我長久以來對於 input/output 的疑惑。 C 語言入門 - 在線上批改系統練功 如何練習使用基本語法 自己出個練習題試著寫...
-
一開始用數學方法推斷得出,設輸入為n k為在n的前一斜線列數,故只要找到 (1+k)*k/2 < n 的最大k值,即可判定 k%2 == 1 => ((2*n)-(k*k)-k)/2 / ((k*k)+(3*k)-(2*n)+4)/2 k%2 ==...