#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 101;
int weight[maxn];
vector<int> v[maxn];
int n, m, s;
vector<int> temppath;
int tempans = 0;
vector<vector<int> > path;
bool cmp(vector<int> p1, vector<int> p2){
int len = max(p1.size(), p2.size());
for(int i = 0; i < len; i++){
if(p1[i] != p2[i]){
return p1[i] > p2[i];
}
}
return p1.size() > p2.size();
}
void dfs(int node){
tempans += weight[node];
temppath.push_back(weight[node]);
if(tempans == s && v[node].empty()){
path.push_back(temppath);
}
if(!v[node].empty()){
for(int i = 0; i < v[node].size(); i++){
dfs(v[node][i]);
}
}
temppath.pop_back();
tempans -= weight[node];
}
int main(){
cin >> n >> m >> s;
for(int i = 0; i < n; i++){
cin >> weight[i];
}
for(int i = 0; i < m; i++){
int node, len, temp;
cin >> node >> len;
for(int j = 1; j <= len; j++){
cin >> temp;
v[node].push_back(temp);
}
}
dfs(0);
sort(path.begin(), path.end(), cmp);
for(int i = 0; i < path.size(); i++){
for(int j = 0; j < path[i].size(); j++){
if(j != 0){
cout << " " << path[i][j];
}else{
cout << path[i][j];
}
}
cout << endl;
}
}
1054 The Dominant Color(20)
#include<cstdio>
#include<map>
using namespace std;
map<int, int> mp;
int main(){
int n, m;
scanf("%d%d", &n, &m);
int temp;
for(int i = 1; i <= m; i++){
for(int j = 1; j <= n; j++){
scanf("%d", &temp);
mp[temp]++;
if(mp[temp] > n * m / 2){
break;
}
}
}
printf("%d", temp);
return 0;
}
1055 The World’s Richest(25)
//超时 每次都排序来不及 直接排一次
// #include<iostream>
// #include<vector>
// #include<algorithm>
// using namespace std;
// const int maxn = 1e5 + 1;
// struct person{
// string name;
// int age, worth;
// }p[maxn];
// vector<person> v;
// bool cmp(person p1, person p2){
// if(p1.worth != p2.worth){
// return p1.worth > p2.worth;
// }
// if(p1.age != p2.age){
// return p1.age < p2.age;
// }
// return p1.name < p2.name;
// }
// int main(){
// int n, k;
// cin >> n >> k;
// for(int i = 0; i < n; i++){
// cin >> p[i].name >> p[i].age >> p[i].worth;
// }
// int num, min_age, max_age;
// for(int i = 1; i <= k; i++){
// cin >> num >> min_age >> max_age;
// v.clear();
// for(int i = 0; i < n; i++){
// if(p[i].age >= min_age && p[i].age <= max_age){
// v.push_back(p[i]);
// }
// }
// printf("Case #%d:\n", i);
// if(v.empty()){
// cout << "None" << endl;
// continue;
// }
// sort(v.begin(), v.end(), cmp);
// for(int i = 0; i < num && i < v.size(); i++){
// printf("%s ",v[i].name.c_str());
// cout << v[i].age << " " << v[i].worth << endl;
// //cout << v[i].name << " " << v[i].age << " " << v[i].worth << endl;
// }
// }
// }
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 1e5 + 1;
struct person{
string name;
int age, worth;
}p[maxn];
bool cmp(person p1, person p2){
if(p1.worth != p2.worth){
return p1.worth > p2.worth;
}
if(p1.age != p2.age){
return p1.age < p2.age;
}
return p1.name < p2.name;
}
int main(){
int n, k;
cin >> n >> k;
for(int i = 0; i < n; i++){
cin >> p[i].name >> p[i].age >> p[i].worth;
}
sort(p, p + n, cmp);
int num, min_age, max_age;
for(int i = 1; i <= k; i++){
cin >> num >> min_age >> max_age;
printf("Case #%d:\n", i);
int u = 0;
int flag = 0;
while(num != 0 && u < n){
if(p[u].age >= min_age && p[u].age <= max_age){
printf("%s ",p[u].name.c_str());
cout << p[u].age << " " << p[u].worth << endl;
num--;
flag = 1;
}
u++;
}
if(flag == 0){
cout << "None" << endl;
}
}
}
1056 Mice and Rice(25)
//开的数组太多了, 不太清晰 还是应该定义结构体
#include<iostream>
#include<queue>
using namespace std;
const int maxn = 1e4 + 1;
int weight[maxn], order[maxn], rk[maxn];
queue<int> q;
int main(){
int np, ng;
cin >> np >> ng;
for(int i = 0; i < np; i++){
cin >> weight[i];
}
for(int i = 0; i < np; i++){
cin >> order[i];
q.push(order[i]);
}
int group_num;
while(!q.empty()){
int size = q.size();
if(size == 1){
rk[q.front()] = 1;
break;
}
if((size / ng) * ng == size){
group_num = size / ng;
}else{
group_num = size / ng + 1;
}
int max_num_index = -1;
int cnt = 0;
for(int i = 0; i < size; i++){
int index = q.front();
rk[index] = group_num + 1;
q.pop();
cnt++;
if(max_num_index == -1 || weight[max_num_index] < weight[index]){
max_num_index = index;
}
if(cnt == ng || i == size - 1){
q.push(max_num_index);
cnt = 0;
max_num_index = -1;
}
}
}
for(int i = 0; i < np; i++){
if(i != 0){
cout << " " << rk[i];
}else{
cout << rk[i];
}
}
}