2022年1月20日 星期四

UVa12970

解題心得

表面上看起來很容易,但牽扯到數字約分就比較複雜。

要記得gcd怎麼寫。

程式碼

#include <iostream>
using namespace std;

long long int gcd(long long int a, long long int b)
{
	while((a%=b)!=0 && (b%=a)!=0);
	return a+b;
}
int main()
{
	int count=1;
	long long int v1, d1, v2, d2;
	while(cin>>v1>>d1>>v2>>d2)
	{
		if(v1==0 && d1==0 && v2==0 && d2==0) break;
		
		cout<<"Case #"<<count++<<": ";
		if(float(d1)/v1 < float(d2)/v2)
			cout<<"You owe me a beer!"<<endl;
		else
			cout<<"No beer for the captain."<<endl;
			
		cout<<"Avg. arrival time: ";
		long long int up, down,_gcd;
		up=d1*v2 + d2*v1;
		down=2*v1*v2;
		_gcd=gcd(up,down);
		
		up/=_gcd, down/=_gcd;
		if(down==1)
			cout<<up<<endl;
		else
			cout<<up<<"/"<<down<<endl;
	}
	return 0;
}

git 指令筆記

push a folder

git remote add origin https://gitlab.com/xxxxx/test.git

git add .

git commit -m “Initial commit”

git push -u origin master  # git push <remote-repo> <branch-name>



view repo's history

git log

git log --oneline

git log --stat # display the files that have been changed in the commit, as well as the number of lines that have been added or deleted

git log -p # display the actual changes made to a file

git log -p <SHA>

git show

git show <SHA>

git diff # see changes that have been made but haven't been committed


git log --oneline --graph --decorate --all

git log --author="Richard Kalehoff"

git log --grep="border radius issue in Safari"


branch

git branch # list all branch

git branch sidebar # create new branch called sidebar

git checkout sidebar # switch to branch sidebar

git branch -d sidebar # delete

git checkout -b footer master # create new branch and switch to it

git checkout -b footer <SHA>


merge

git merge <branch-name> # merge <branch-name> into current branch

# to fix conflict:

# open editor and fixed it

# commit again


amend commit

git commit --amend

# if  Working Directory is clean

# change the commit message

# else

# update all change within the staging area



git revert <SHA-of-commit-to-revert>



Udacity Git Commit Message Style Guide

2022年1月19日 星期三

UVa10222

解題心得

太久沒寫C++,差點忘了字串處理的部分。

程式碼

#include <iostream>
using namespace std;

int main()
{
	string table = "qwertyuiop[]\\asdfghjkl;'zxcvbnm,./";
	int T;
	cin>>T;
	cin.ignore();
	
	while(T--)
	{
		string s;
		getline(cin,s);
		
		for(int i=0;i<s.length();i++)
		{
			if(isupper(s[i])) s[i] = (s[i]-'A')+'a';
			if(s[i]==' ')
			{
				cout<<" ";
				continue;
			}
			
			for(int j=0;j<table.length();j++)
			{
				if(table[j]==s[i])
				{
					cout<<table[((j-2)+table.length())%table.length()];
				}
			}
		}
		cout<<endl;
	}
	return 0;
}

UVa12959

解題心得

沒有心得

程式碼

#include <iostream>
using namespace std;

int main()
{
	int T;
	cin>>T;
	
	while(T--)
	{
		int n, max=0, ans=-999999,temp;
		cin>>n;

		for(int i=0;i<n;i++)
		{
			cin>>temp;
			
			if(i==0)
			{
				max = temp;
				continue;
			}
			
			if(max-temp>ans)
				ans = max-temp;
			if(temp>max)
				max=temp;
		}
		cout<<ans<<endl;
	}
	return 0;
}

UVa11078

解題心得

不能用暴力解,會TLE。

可以一邊讀新的數字進來,一邊紀錄是不是目前遇到的最大值,並且把之前紀錄的最大值跟當下吃到的數字比較,如果比較大就記起來。

程式碼

#include <iostream>
using namespace std;

int main()
{
	int T;
	cin>>T;
	
	while(T--)
	{
		int n, max=0, ans=-999999,temp;
		cin>>n;

		for(int i=0;i<n;i++)
		{
			cin>>temp;
			
			if(i==0)
			{
				max = temp;
				continue;
			}
			
			if(max-temp>ans)
				ans = max-temp;
			if(temp>max)
				max=temp;
		}
		cout<<ans<<endl;
	}
	return 0;
}

UVa118

解題心得

嗚嗚

程式碼

#include <iostream>
using namespace std;

int main()
{
	int Xmax, Ymax, x, y, grid[51][51] = { 0 };
	char orient;
	string s;

	cin >> Xmax >> Ymax;
	while (cin >> x >> y >> orient)
	{
		bool isLost = false;

		cin >> s;
		for (int i = 0; i < s.length(); i++)
		{
			if (s[i] == 'L')
			{
				if (orient == 'N') orient = 'W';
				else if (orient == 'E') orient = 'N';
				else if (orient == 'S') orient = 'E';
				else if (orient == 'W') orient = 'S';
			}
			else if (s[i] == 'R')
			{
				if (orient == 'N') orient = 'E';
				else if (orient == 'E') orient = 'S';
				else if (orient == 'S') orient = 'W';
				else if (orient == 'W') orient = 'N';
			}
			else
			{
				int next_x = x, next_y = y;
				if (orient == 'N') next_y++;
				else if (orient == 'E') next_x++;
				else if (orient == 'S') next_y--;
				else if (orient == 'W') next_x--;

				if (next_x<0 || next_y<0 || next_x>Xmax || next_y>Ymax)
				{
					if (grid[x][y] == 1)
						continue;

					isLost = true;
					grid[x][y] = 1;
					break;
				}
				x = next_x, y = next_y;
			}
			
		}
		cout << x << " " << y << " " << orient;
		if (isLost)
			cout << " LOST";
		cout << endl;
	}
	return 0;
}

2022年1月18日 星期二

UVa11728

解題心得

暴力解

程式碼

#include <iostream>
using namespace std;

int factor_sum(int n)
{
	int sum = 0;
	
	for (int i = 1; i <= n; i++)
	{
		if (n % i == 0)
			sum += i;
	}
	return sum;
}

int main()
{
	int S, count = 1;
	while (cin >> S)
	{
		if (S == 0) break;
		cout << "Case " << count++ << ": ";

		int ans = -1;
		for (int i = 1; i < S; i++)
		{
			if (factor_sum(i) == S)
			{
				ans = i;
			}
		}
		if (S == 1)
			ans = 1;
		cout << ans << endl;
	}
	return 0;
}

UVa1260

解題心得

沒有心得

程式碼

#include <iostream>
using namespace std;

int main()
{
	int T, n;
	cin>>T;
	while(T--)
	{
		cin>>n;
		int sales[1001]={0};
		for(int i=0;i<n;i++)
		{
			cin>>sales[i];
		}
		int ans=0;
		for(int i=1;i<n;i++)
		{
			for(int j=0;j<i;j++)
			{
				if(sales[j]<=sales[i])
					ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

UVa12650

解題心得

沒有心得

程式碼

#include <iostream>
using namespace std;

int main()
{
	int N,R;
	while(cin>>N>>R)
	{
		int card[N+1]={0}, flag=0;
		for(int i=0;i<R;i++)
		{
			cin>>flag;
			card[flag]=1;
		}
		if(N==R)
			cout<<"*"<<endl;
		else
		{
			for(int i=1;i<=N;i++)
			{
				if(card[i]==0)
					cout<<i<<" ";
			}
			cout<<endl;
		}
	}
	return 0;
}

2021年12月28日 星期二

看論文的網站

 https://arxiv.org/

通常比較新的paper可以在這裡找到。有時候論文從投稿到被接受可能長達一年,原因是流程繁瑣、被搞等等,總之為了避免在此期間有人搶先發表搶走credit,會在這裡先發。論文品質不一。

IEEE: conference跟journal上都是很好的論文

acm T開頭相關的都值得看(?)

google scholar可以看論文被引用過幾次、分別是哪篇


資安相關的conference可以參考:https://people.engr.tamu.edu/guofei/sec_conf_stat.htm

前面四個最頂,台灣人投上也沒幾個。


MobiCom、infocom是通訊領域的知名conference


選哪些paper報:

先從上面提到的那些來找論文,看被cite或reference。如果該篇論文的conference名氣小但很新,可能是技術剛發展,也許還是有看的價值;如果該篇論文舊(ex:三年前)、conference沒啥名氣而且cite數也不多,那基本上就不用看了,除非是競爭對手的文章,要研究他的動向(?)


因為時間精力有限,才要懂得從論文名字、摘要,或者引用等等來判斷論文需不需要讀。花幾周讀不重要的論文只是浪費時間。以及正因如此,才要在其他人報paper的時候吸收學習。

2021年10月21日 星期四

[loveless] 單字筆記

form-room: (中小)學生早晨接受點名的教室

sleepover: 過夜

word for word: 逐字的、一字不差的

truth or dare: 真心話大冒險

chorus: 異口同聲 

interject: 插話

outrage: 憤怒

drawl: 說話拉長音,說話拉長調子

cackle: 格格笑

berate: 斥責

mascara: 睫毛膏

smudge: (擦拭後留下的)汙跡,污痕

radiator: 暖氣裝置

ajar: 半開的

eyeful: 滿眼的

on and off: 間歇的

sparkly: 閃閃發光

knit: 針織

geriatric: 老年的

unfazed: 不為所動

slouch: 無精打埰地站(或坐、走)

orgy: (尤指縱情酒色或毒品的)狂歡聚會

eyelash: 睫毛

giddy: 頭暈

unbridled: 肆無忌憚

topple: 傾倒

numeracy: 算術

climbing frame: 攀爬架

leavers: 離校生

unscathed: 毫髮無損

commotion: 騷動

pull up: (某人)把車停下

sink in: (事實或想法)逐漸被完全理解,被充分意識到

slur: 含糊不清地說話

prod: (用手指、尖物等)刺,捅;戳

chastise: 責備

barrage: 接二連三的

boot: (汽車後部的)行李箱,後備箱

hideously: 極其

cobble: 鵝卵石

candid: 坦率

allegiance: 忠誠

get cracking: to start doing something quickly

fern: 蕨類

whoosh: 嗖的一聲;呼的一聲

splash of colour: https://hinative.com/zh-TW/questions/4147444

carpet: 地毯

mouldy: 發霉的

beige: 淺褐色

sash:(門窗上鑲玻璃的)窗框

meadow: 草地、牧場

fleece: 羊毛

duvet: 羽絨被

mumble: 咕噥

relegate: 貶謫

branch out: 涉足(尤指新工作);擴展(業務)

ramble: 語無倫次地閒扯;沒完沒了地胡亂說

slump: 沈重地坐下(或倒下)

stock photo: 供設計公司和廣告商即時使用的現成相片,通常是由想找些外快的業餘攝影師所拍攝。

fairy lights:(尤指聖誕樹上的)彩色小燈

shaggy: (毛髮)粗長而蓬亂的

give sth/sb the once-over: 對…草草檢查一下;對…走馬看花地看一遍

banter: 開玩笑

fluffy: 毛茸茸的、蓬鬆的

stan: 瘋狂追星

trot: 小跑

unerring: 永不犯錯的;一貫正確的

mingle:(在社交場合)相交往,相往來

posh: 高檔的

hook up: 勾搭、約炮

Matriculation: 大學入學 

sprawl: (懶散地)攤開四肢坐(或躺)

hallmark: 特點

fixation: 異常依戀,固戀;癖

joke aside: 言歸正傳,說正經的

ramble: 漫談

at length: 仔細的

headboard: 床頭板

oblivious: (尤指對周圍發生的事情)毫不在意的,毫無知覺的,未察覺的

jarring: 令人感到不快的;刺激(神經等)的

mundane: 世俗的;單調的;平凡的

slim: 苗條的

bomber jacket: 飛行夾克

tartan: 花呢格紋

enamel: 瓷釉

glitter: 閃光

confetti: 五彩紙屑

onlooker: 旁觀者

archaic: 古老的、過時的

nasty: 可惡的

make a face: 做鬼臉

unnerving: 令人不安的

barge: (魯莽地)衝,闖

under your breath: 低聲地,輕聲地

well up: https://hinative.com/zh-TW/questions/4698861

fiasco: 慘敗

vicinity: 附近

leer: (尤指男人)不懷好意地看,好色地看,色迷迷地看

dimple: 酒窩

amble: 漫步;緩行

woolly: 毛茸茸的

smutty: 淫穢下流

take aback: 大吃一驚

sort out: 解決、處理

fluster: 使心煩意亂;使緊張

banter: (善意地)取笑,逗弄

peppy: 精力充沛的,生氣勃勃的

hunch: 弓(背),彎腰

make a scene: 當眾吵鬧

wardrobe: 衣櫃

exude: 發散著

bagsy: 先說先佔權

crayon: 蠟筆

contender: 競爭者

grimly: 冷酷的

feud: 世仇

nudge: (尤指用肘部)輕推

reiterate: 重申

procure: 採購

sneak off: 偷偷跑走

crouch: 蹲伏

cape: 披肩

hanger: 衣架

bleary: 惺忪的

worn out: 精疲力盡

press-gang: 強迫

steadfastly: 堅定的

rummage: 翻找出

rucksack: 背包

reminisce: 回憶

anecdote: 奇聞軼事

snobbery: 勢利

falter: 衰弱;動搖;猶豫;畏縮

conjure: 變戲法

deadpan: 故作正經的

bicker: 鬥嘴

crux: 癥結

budge up:挪一挪;讓開

biscuit: 餅乾

cosiness: 舒適

pastel: 粉彩

lament: 哀嘆

dwindle: 縮小

shithead: 白癡、笨蛋

platonic: 柏拉圖式的

rundown: 詳細報告

blunt: 直率的;生硬的;直截了當的

chilling in: 放鬆

escapade:冒險行爲;尋求刺激的行爲;惡作劇

same difference: 差不多一樣

troupe: 劇團

commence: 開始

one-up: 勝過一籌

yikes:(表示驚訝、擔憂等)呀

rickety: 搖搖晃晃的

endearing:使人喜愛的

squawk: 發牢騷

ginormous: 巨大的

fire away: 儘管問吧

the worse for wear: (人)筋疲力盡的;(物品)破損不堪的,破舊的

call it a day: 結束工作;到此為止;收工

comfort food: (難過或焦慮時食用的)安慰食品,開心食品

get cold feet:(尤指面對結婚等重要事宜時)突然退縮,裹足不前

tag along: (通常指未經邀請)跟隨,尾隨

Glue At The Hip: (人)黏在一起

fed up with: 厭倦的;厭煩的;失望的

self-assured: 自信的

run into: 巧遇

sinister: 不祥的

nosy: 好管閒事的;愛打聽的

blink: 眨(眼睛)

ballpark: 大約估計

mingle: (在社交場合)相交往,相往來

bigot: 偏執的人,固執己見的人

trail off:(說話聲或類似聲響)逐漸減弱到停止,逐漸消失

scuff: 磨損,磨壞(尤指鞋或地板)

scrawl: 潦草地寫;亂塗

dance floor: (夜總會、餐館等的)舞池

go overboard: 做得過頭;過分激動;過分熱衷

snicker: 暗笑

transfixed: 呆若木雞

fast friend: 可靠的朋友

recoil: 畏縮

If x is anything to go by: 根據過去的經驗

bicker over: 為某事鬥嘴

deal breaker: 阻礙成功交易的關鍵因素

misogynist: 厭女者

abs: 腹肌

sludge: 汙泥

sincerity: 誠意

situate: 位於

crack a smile: to smile slightly

migraine: 偏頭痛

dumbfounded: 嚇得目瞪口呆的,驚得說不出話的

blurt: 脫口而出

nudge: 輕推

burglar: 入室竊賊

yank: 猛拉;猛拽

God forbid: 但願不會發生這事

teary: 哭泣的,流淚的

tear-stained: 淚濕的

wilt: 枯萎

drool: 流口水

zone out: 走神

salvage: 搶救

akin: 類似於

wistful: 惆悵的

foyer:(劇院、飯店等公共建築物入口處內的)門廳, (房子或公寓的)門廊

bouncy castle: 充氣城堡

fortitude: 堅毅

swimming pool noodles: 自行google吧

crutch: 拐杖

jab: 戳

beanbag: 懶骨頭

crux: 癥結

woe: 災難、不幸

clusterfuck: 大規模混亂;錯誤連連的災難性局面

you do you: Do what you want. Be yourself.

vape pen: 電子煙

snap: 厲聲說

nasty: 糟糕的;令人不快的,讓人討厭的

crack a joke: 講笑話

rip: 迅速扯開;猛力去除

clapback: (對批評或侮辱自己的人做出的)幽默回應,巧妙回擊

fathom: 弄清;理解

savoury: 鹹味的

rewind: 倒回(磁帶);倒(帶);倒(片)

damp: 潮濕

pester: 不斷煩擾,糾纏

life jacket: 救生衣

megaphone: 大聲公

dumbass: 蠢貨

bedhead:(因為剛起床)一頭亂髮