From 9239c6b90a36e83825e3c66946f0b402ed923576 Mon Sep 17 00:00:00 2001 From: Oliver Bao Date: Thu, 20 Apr 2017 22:11:33 +0800 Subject: [PATCH 1/4] Add Codeforces247A.cpp --- royecode/Codeforces247A.cpp | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 royecode/Codeforces247A.cpp diff --git a/royecode/Codeforces247A.cpp b/royecode/Codeforces247A.cpp new file mode 100644 index 0000000..2076e50 --- /dev/null +++ b/royecode/Codeforces247A.cpp @@ -0,0 +1,48 @@ +/* ACMer: royecode + * Date: 2017-04-20 + * 题目链接: http://codeforces.com/contest/274/problem/A + * 题目大意: 给一个集合有n个数,一个k,需要剔除这个集合中满足如下的数: + * y > x 并且 y = x * k + * + * + * 解题思路: 很明显去枚举y然后找x,用一个set维护一下答案,当然需要对 + * 输入的数做个排序 + * + * + */ +//代码部分 +// +#include +#include +#include + +using namespace std; + +int main() +{ + int n, k; + cin >> n >> k; + set arr; + set ans; + + for(int i = 0; i < n; ++i) + { + int val; + cin >> val; + arr.insert(val); + } + + for(set::iterator begin = arr.begin(); begin != arr.end(); ++begin) + { + int val = *begin; + // 枚举y,如果y在答案的集合中则跳过 + if(val % k == 0 && ans.find(val / k) != ans.end()) + { + continue; + } + ans.insert(val); + } + + cout << ans.size() << endl; + return 0; +} From fde5efaa2c093b905ff4bc0c3acce543b26e372d Mon Sep 17 00:00:00 2001 From: Oliver Bao Date: Sat, 22 Apr 2017 11:37:02 +0800 Subject: [PATCH 2/4] Solve new Problem of Contest div2 A --- royecode/Codeforces4102A.cpp | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 royecode/Codeforces4102A.cpp diff --git a/royecode/Codeforces4102A.cpp b/royecode/Codeforces4102A.cpp new file mode 100644 index 0000000..6dc1737 --- /dev/null +++ b/royecode/Codeforces4102A.cpp @@ -0,0 +1,52 @@ +/* ACMer: royecode + * Date: 2017-04-22 + * 棰樼洰閾炬帴: http://codeforces.com/contest/798/problem/A + * 棰樼洰澶ф剰: 闂瓧绗︿覆s锛岃兘鍚︿粎浠呮敼鍙樹竴涓瓧绗︼紝浣縮涓哄洖鏂 + * 鑳藉垯YES锛屽惁鍒橬O + * + * + * 瑙i鎬濊矾: 浠nt涓猴細浣縮涓哄洖鏂囩殑鏈灏忔敼鍙樻鏁 + * 鏈変袱绉嶆儏鍐典负YES锛宑nt涓1锛屾垨cnt绛変簬0骞朵笖s鐨勫ぇ灏 + * 涓哄鏁般 + * 褰撳垵鑰冭檻涓嶅畬鍏ㄦ妸锛學rong浜2娆★紝灏村艾锛 + * + * + */ +//浠g爜閮ㄥ垎 +// +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAXN 100007 + +using namespace std; + +int main() +{ + std::ios_base::sync_with_stdio(false); + string st; + cin >> st; + int times = 0; + for(int i = 0; i < st.length() / 2; ++i) + { + if(st[i] != st[st.length() - 1 - i]) + { + times += 1; + } + } + if(times == 1 || (times == 0 && st.length() % 2 == 1)) + { + cout << "YES" << endl; + } + else + { + cout << "NO" << endl; + } + return 0; +} From 26f8aee530b1c273724f2a192b60a09a73cb89a3 Mon Sep 17 00:00:00 2001 From: Oliver Bao Date: Sat, 22 Apr 2017 11:42:06 +0800 Subject: [PATCH 3/4] New Problme Codeforces410Div2B.cpp --- royecode/Codeforces410Div2B.cpp | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 royecode/Codeforces410Div2B.cpp diff --git a/royecode/Codeforces410Div2B.cpp b/royecode/Codeforces410Div2B.cpp new file mode 100644 index 0000000..57f0c19 --- /dev/null +++ b/royecode/Codeforces410Div2B.cpp @@ -0,0 +1,79 @@ +/* ACMer: royecode + * Date: 2017-04-22 + * 棰樼洰閾炬帴: http://codeforces.com/contest/798/problem/B + * 棰樼洰澶ф剰: n涓瓑澶у皬鐨勫瓧绗︿覆锛屽畾涔夌Щ鍔ㄤ竴姝ワ細灏嗛瀛楃绉诲姩 + * 鏈熬锛岀敤鏈灏忕殑绉诲姩灏唍涓瓧绗︿覆鍙樻垚涓鏍风殑锛岃嫢涓 + * 瀹屾垚杈撳嚭-1 + * + * + * 瑙i鎬濊矾: 鐢变簬瀛楃涓茬殑澶у皬涓嶈秴杩50锛屾墍浠ュ彲浠ョ洿鎺ユ毚鍔涙ā鎷 + * 鏃堕棿澶嶆潅搴(n^3) + * + */ +//浠g爜閮ㄥ垎 +// +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAXN 100007 + +using namespace std; + +bool transform(string gold, string src, int &num) +{ + while(gold != src && num < gold.length()) + { + src = src.substr(1, src.length() - 1) + src[0]; + num += 1; + } + + if(num == gold.length()) + { + return false; + } + return true; +} + +int main() +{ + std::ios_base::sync_with_stdio(false); + int n; + cin >> n; + vector st; + + for(int i = 0; i < n; ++i) + { + string temp; + cin >> temp; + st.push_back(temp); + } + + int ans = 10000007; + for(int i = 0; i < n; ++i) + { + string gold = st[i]; + int count = 0; + for(int i = 0; i < n; ++i) + { + int num = 0; + if(!transform(gold, st[i], num)) + { + cout << -1 << endl; + return 0; + } + + count += num; + } + + ans = min(ans, count); + } + + cout << ans << endl; + return 0; +} From 8061794ad39d7e3a8894232ae1dfa041ad4b16c8 Mon Sep 17 00:00:00 2001 From: Oliver Bao Date: Sat, 22 Apr 2017 12:39:16 +0800 Subject: [PATCH 4/4] Solve New Problem Codeforces contest 247 B --- royecode/Codeforces247B.cpp | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 royecode/Codeforces247B.cpp diff --git a/royecode/Codeforces247B.cpp b/royecode/Codeforces247B.cpp new file mode 100644 index 0000000..5ae7399 --- /dev/null +++ b/royecode/Codeforces247B.cpp @@ -0,0 +1,71 @@ +/* ACMer: royecode + * Date: 2017-04-20 + * 题目链接: http://codeforces.com/contest/274/problem/B + * 题目大意: n个节点的树,n - 1条边,每个节点有个值v + * 每次你可以对一个子树(此子树必须包含1这个节点)的每个节点加1或减1 + * 用最少的步数,使这棵树的所有节点值为0 + * + * + * 解题思路: 可以用dfs来解决,维护一个加1和减1数组,即可 + * + * PS: 当初想了很久,不是用这种方法解决的,Wrong了很多次 + * 之后看了别人的代码才看懂了!!啊啊!! + * + */ +//代码部分 +// +#include +#include +#include + +using namespace std; + +typedef long long ll; +typedef pair pll; +const int N = 100007; + +int v[N]; +vector g[N]; + +pll dfs(int u, int p) +{ + ll inc = 0, dec = 0; + for(int i = 0; i < g[u].size(); ++i) + { + int v = g[u][i]; + if (v == p) continue; + + pll sub = dfs(v,u); + inc = max(inc, sub.first); + dec = max(dec, sub.second); + } + + v[u] += inc - dec; + if(v[u] > 0) dec += v[u]; + else inc += -v[u]; + + return {inc, dec}; +} + +int main() +{ + int n; + cin >> n; + for(int i = 0; i < n - 1; ++i) + { + int x, y; + cin >> x >> y; + g[x].push_back(y); + g[y].push_back(x); + } + + for(int i = 1; i <= n; ++i) + { + cin >> v[i]; + } + + pll ret = dfs(1, -1); + + cout << ret.first + ret.second << endl; + return 0; +}