-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit 0dc6388.
- Loading branch information
Showing
13 changed files
with
989 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <algorithm> | ||
#include <vector> | ||
|
||
#include <cstdio> | ||
#include <cmath> | ||
#include <cstdlib> | ||
#include <cstring> | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char* argv[]) { | ||
int n; | ||
vector<double> v1(1001, 0); | ||
vector<double> v2(1001, 0); | ||
int k; | ||
double a; | ||
|
||
scanf("%d", &n); | ||
for(int i = 0; i < n; ++i) { | ||
scanf("%d%lf", &k, &a); | ||
v1[k] = a; | ||
} | ||
scanf("%d", &n); | ||
for(int i = 0; i < n; ++i) { | ||
scanf("%d%lf", &k, &a); | ||
v2[k] = a; | ||
} | ||
int count = 0; | ||
for(int i = 0; i <= 1000; ++i) { | ||
v1[i] += v2[i]; | ||
if(v1[i] != 0) | ||
++count; | ||
} | ||
printf("%d", count); | ||
for(int i = 1000; count > 0 && i >= 0 ; --i) { | ||
if(v1[i] == 0) | ||
continue; | ||
--count; | ||
printf(" %d %.1f", i, v1[i]); | ||
} | ||
printf("\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <algorithm> | ||
#include <vector> | ||
|
||
#include <cstdio> | ||
#include <cmath> | ||
#include <cstdlib> | ||
#include <cstring> | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char* argv[]) { | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <algorithm> | ||
#include <vector> | ||
|
||
#include <cstdio> | ||
#include <cmath> | ||
#include <cstdlib> | ||
#include <cstring> | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char* argv[]) { | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
#include <iostream> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <algorithm> | ||
#include <map> | ||
#include <set> | ||
#include <vector> | ||
#include <string> | ||
|
||
//#define DEBUG | ||
|
||
|
||
using namespace std; | ||
|
||
const int MINNUM = 2; | ||
vector<int> pre; | ||
vector<int> bingNum; | ||
|
||
class Record{ | ||
public: | ||
string a; | ||
string b; | ||
int weight; | ||
Record(string tmp1, string tmp2, int tmp3):a(tmp1), b(tmp2), weight(tmp3){}; | ||
}; | ||
|
||
class intRecord { | ||
public: | ||
int a; | ||
int b; | ||
intRecord(int tmp1, int tmp2):a(tmp1), b(tmp2){}; | ||
}; | ||
|
||
class Gang{ | ||
public: | ||
string head; | ||
int num; | ||
Gang(string tmp1, int tmp2):head(tmp1), num(tmp2){}; | ||
}; | ||
|
||
bool cmp(const Gang &lhs, const Gang &rhs) { | ||
return lhs.head < rhs.head; | ||
} | ||
|
||
int findRoot(int a) { | ||
int cur = a; | ||
while(cur != pre[cur]) { | ||
cur = pre[cur]; | ||
} | ||
return cur; | ||
} | ||
|
||
void merge(int a, int b) { | ||
int ra = findRoot(a), rb = findRoot(b); | ||
if(ra == rb) | ||
return; | ||
if(bingNum[ra] < bingNum[rb]) { | ||
pre[ra] = rb; | ||
} | ||
else { | ||
pre[rb] = ra; | ||
if(bingNum[ra] == bingNum[rb]) | ||
bingNum[ra]++; | ||
} | ||
} | ||
|
||
|
||
int main(int argc, char *argv[]) { | ||
#ifdef DEBUG | ||
freopen("in.txt", "r", stdin); | ||
freopen("out.txt", "w", stdout); | ||
#else | ||
#endif | ||
int N, K; | ||
scanf("%d%d", &N, &K); | ||
vector<Record> records; | ||
set<string> s; | ||
for(int i = 0; i < N; ++i) { | ||
string tmp1, tmp2; | ||
int tmp3; | ||
cin >> tmp1 >> tmp2 >> tmp3; | ||
records.push_back(Record(tmp1, tmp2, tmp3)); | ||
s.insert(tmp1); | ||
s.insert(tmp2); | ||
} | ||
map<string, int> name2id; | ||
map<int, string> id2name; | ||
int i = 0; | ||
for(set<string>::iterator iter = s.begin(); iter != s.end(); ++iter, ++i) { | ||
name2id[ (*iter) ] = i; | ||
id2name[ i ] = (*iter); | ||
} | ||
int num = s.size(); | ||
vector<int> gangW(num, 0); | ||
vector<intRecord> intRecords; | ||
|
||
for(int i = 0; i < records.size(); ++i) { | ||
int tmp1 = name2id[ records[i].a ], tmp2 = name2id[ records[i].b ]; | ||
//if(tmp1 == tmp2) | ||
// continue; | ||
gangW[tmp1] += records[i].weight; | ||
gangW[tmp2] += records[i].weight; | ||
intRecords.push_back(intRecord(tmp1, tmp2)); | ||
} | ||
|
||
// bing cha | ||
for(int i = 0; i < num; ++i) | ||
pre.push_back(i); | ||
for(int i = 0; i < num; ++i) | ||
bingNum.push_back(1); | ||
|
||
for(int i = 0; i < intRecords.size(); ++i) { | ||
merge(intRecords[i].a, intRecords[i].b); | ||
} | ||
|
||
map< int, vector<int> > links; | ||
set<int> ids; | ||
for(int i = 0; i < num; ++i) { | ||
int id = findRoot(i); | ||
links[ id ].push_back(i); | ||
ids.insert( id ); | ||
} | ||
vector<Gang> result; | ||
for(set<int>::iterator iter = ids.begin(); iter != ids.end(); ++iter) { | ||
int id = *iter; | ||
if(links[id].size() <= MINNUM) | ||
continue; | ||
int sum = 0; | ||
for(int i = 0; i < links[id].size(); ++i) { | ||
sum += gangW[ links[id][i] ]; | ||
} | ||
if(sum / 2 <= K) | ||
continue; | ||
int head = 0; | ||
for(int i = 0; i < links[id].size(); ++i) { | ||
if(gangW[ links[id][i] ] > gangW[ links[id][head] ]) { | ||
head = i; | ||
} | ||
} | ||
result.push_back( Gang( id2name[ links[id][head] ], links[id].size() ) ); | ||
} | ||
|
||
sort(result.begin(), result.end(), cmp); | ||
cout << result.size() << endl; | ||
|
||
for(int i = 0; i < result.size(); ++i) { | ||
cout << result[i].head << " " << result[i].num << endl; | ||
} | ||
|
||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
#include <algorithm> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
|
||
using namespace std; | ||
|
||
bool cmp(const string &lhs, const string &rhs){ | ||
string a = lhs, b = rhs; | ||
a.append(rhs); | ||
b.append(lhs); | ||
return a < b; | ||
} | ||
|
||
int main(int argc, char *argv) { | ||
#ifndef ONLINE_JUDGE | ||
freopen("in.txt", "r", stdin); | ||
freopen("out.txt", "w", stdout); | ||
#endif | ||
|
||
int n; | ||
cin >> n; | ||
vector<string> v(n); | ||
for(int i = 0; i < n; ++i) | ||
cin >> v[i]; | ||
sort(v.begin(), v.end(), cmp); | ||
bool start = false; | ||
for(int i = 0; i < v.size(); ++i) { | ||
if(start) { | ||
cout << v[i]; | ||
} | ||
else { | ||
for(int j = 0; j < v[i].size(); ++j) { | ||
if(start) { | ||
cout << v[i][j]; | ||
} | ||
else if(!start && '0' != v[i][j]) { | ||
start = true; | ||
cout << v[i][j]; | ||
} | ||
} | ||
} | ||
} | ||
if(!start) | ||
cout << "0"; | ||
cout << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <queue> | ||
#include <algorithm> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <cstring> | ||
|
||
using namespace std; | ||
|
||
int f[20]; | ||
|
||
struct node { | ||
int val; | ||
node *left; | ||
node *right; | ||
}; | ||
|
||
int getRootPos(int n) { | ||
if(0 == n) | ||
return 0; | ||
if(1 == n) | ||
return 1; | ||
|
||
int height = 0; | ||
int i = 0; | ||
for(; i < 20; ++i) { | ||
if(n < f[i]) | ||
break; | ||
} | ||
height = i; | ||
int remain = min( n - f[height - 1], (f[height] - f[height-1]) / 2 ); | ||
return (f[height - 1] - 1) / 2 + remain + 1; | ||
} | ||
|
||
node* getResult(const vector<int> &v, int startPos, int endPos) { | ||
int n = endPos - startPos + 1; | ||
if(n <= 0) | ||
return NULL; | ||
int rootPos = getRootPos(n); | ||
node* root = new node(); | ||
root->val = v[ startPos + rootPos -1 ]; | ||
root->left = getResult(v, startPos, startPos + rootPos - 2); | ||
root->right = getResult(v, startPos + rootPos, endPos); | ||
return root; | ||
} | ||
|
||
void printTree(node *root) { | ||
if(root == NULL) | ||
return; | ||
queue<node *> q; | ||
vector<int> v; | ||
q.push(root); | ||
while(q.size() != 0) { | ||
v.push_back(q.front()->val); | ||
if(NULL != q.front()->left) | ||
q.push(q.front()->left); | ||
if(NULL != q.front()->right) | ||
q.push(q.front()->right); | ||
q.pop(); | ||
} | ||
printf("%d", v[0]); | ||
for(int i = 1; i < v.size(); ++i) { | ||
printf(" %d", v[i]); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
int main(int argc, char *agrv[]) { | ||
// 2 pow | ||
int base = 1; | ||
for(int i = 0; i < 20; ++i) { | ||
f[i] = base; | ||
base *= 2; | ||
} | ||
for(int i = 1; i < 20; ++i) { | ||
f[i] += f[i-1]; | ||
} | ||
|
||
// get input | ||
int n; | ||
scanf("%d", &n); | ||
if(0 == n) | ||
return 0; | ||
|
||
vector<int> v(n); | ||
for(int i = 0; i < n; ++i) { | ||
scanf("%d", &v[i]); | ||
} | ||
|
||
// | ||
sort(v.begin(), v.end()); | ||
vector<int> result; | ||
node *root = getResult(v, 0, v.size()-1); | ||
|
||
// print result; | ||
printTree(root); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.