Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions royecode/Codeforces247A.cpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>
#include <vector>
#include <set>

using namespace std;

int main()
{
int n, k;
cin >> n >> k;
set<int> arr;
set<int> ans;

for(int i = 0; i < n; ++i)
{
int val;
cin >> val;
arr.insert(val);
}

for(set<int>::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;
}
71 changes: 71 additions & 0 deletions royecode/Codeforces247B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* ACMer: royecode
* Date: 2017-04-20
* ��Ŀ����: http://codeforces.com/contest/274/problem/B
* ��Ŀ����: n���ڵ������n - 1���ߣ�ÿ���ڵ��и�ֵv
* ÿ������Զ�һ���������������������1����ڵ㣩��ÿ���ڵ��1���1
* �����ٵIJ�����ʹ����������нڵ�ֵΪ0
*
*
* ����˼·: ������dfs�������ά��һ����1�ͼ�1���飬����
*
* PS: �������˺ܾã����������ַ�������ģ�Wrong�˺ܶ��
* ֮���˱��˵Ĵ���ſ����ˣ�����������
*
*/
//���벿��
//
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
const int N = 100007;

int v[N];
vector<int> 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;
}
52 changes: 52 additions & 0 deletions royecode/Codeforces4102A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* ACMer: royecode
* Date: 2017-04-22
* 题目链接: http://codeforces.com/contest/798/problem/A
* 题目大意: 问字符串s,能否仅仅改变一个字符,使s为回文
* 能则YES,否则NO
*
*
* 解题思路: 令cnt为:使s为回文的最小改变次数
* 有两种情况为YES,cnt为1,或cnt等于0并且s的大小
* 为奇数。
* 当初考虑不完全把,Wrong了2次,尴尬!
*
*
*/
//代码部分
//
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iterator>

#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;
}
79 changes: 79 additions & 0 deletions royecode/Codeforces410Div2B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* ACMer: royecode
* Date: 2017-04-22
* 题目链接: http://codeforces.com/contest/798/problem/B
* 题目大意: n个等大小的字符串,定义移动一步:将首字符移动
* 末尾,用最小的移动将n个字符串变成一样的,若不
* 完成输出-1
*
*
* 解题思路: 由于字符串的大小不超过50,所以可以直接暴力模拟
* 时间复杂度O(n^3)
*
*/
//代码部分
//
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iterator>

#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<string> 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;
}