两题签到。。。
(后续补题)
A题
链接:https://www.nowcoder.com/acm/contest/144/A
来源:牛客网
可以直接暴力模拟,其实本身是个完全二叉树的模子 所有用树来模拟更快些
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 33000;
vector<int> a[N];
int n;
int tree[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
for(int num = 1;num <= t;num ++)
{
memset(tree,0,sizeof(tree));
for(int i = 0;i < N;i ++)
a[i].clear();
cin >> n;
int sp = pow(2,n);
int ts;
for(int i = 1;i <= sp;i ++) // 总人数
{
for(int j = 1;j <= n;j ++) // 每个人n首歌
{
cin >> ts;
a[i].emplace_back(ts);
}
sort(a[i].begin(),a[i].end());
}
//建立竞赛树
int sta = sp;
for(int i = 1;i <= sp;i ++)
{
tree[sta++] = i;
}
int pos = sp;
while(1)
{
for(int i = pos;i < 2 * pos - 1;i += 2)
{
int max_1 = a[tree[i]][a[tree[i]].size()-1];
int max_2 = a[tree[i+1]][a[tree[i+1]].size()-1];
if(max_1 > max_2)
{
auto outpos = upper_bound(a[tree[i]].begin(), a[tree[i]].end(), max_2);
a[tree[i]].erase(outpos);
tree[i/2] = tree[i];
}
else
{
auto outpos = upper_bound(a[tree[i+1]].begin(), a[tree[i+1]].end(), max_1);
a[tree[i+1]].erase(outpos);
tree[(i+1)/2] = tree[i+1];
}
}
pos /= 2;
if(pos == 1)
break;
}
printf("Case #%d: %d\n",num,tree[1]);
}
return 0;
}
链接:https://www.nowcoder.com/acm/contest/144/D
来源:牛客网
真·签到
每个身体只能配一个脸 所有找权值最大的 最后把所有body配的weight加到一块就行了
#include <bits/stdc++.h>
using namespace std;
long long work() {
int n , m , k;
scanf("%d%d%d" , &n , &m , &k);
vector<int> w(m);
for (int i = 0 ; i < k ; ++ i) {
int x , y , z;
scanf("%d%d%d" , &x, &y , &z);
w[y - 1] = max(w[y - 1] , z);
}
long long res = 0;
for (int i = 0 ; i < m; ++ i) {
res += w[i];
}
return res;
}
int main() {
int T;
scanf("%d" , &T);
while (T --) {
static int ca = 0;
printf("Case #%d: %lld\n" , ++ ca , work());
}
}
毒瘤题。。。
链接:https://www.nowcoder.com/acm/contest/144/J
来源:牛客网
选出前100大的数平方暴力即可,随机两个数互质的概率为 6/Π^2
#include <bits/stdc++.h>
using namespace std;
unsigned a[10000000];
unsigned x, y, z;
unsigned tang() {
unsigned t;
x ^= x << 16;
x ^= x >> 5;
x ^= x << 1;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
return z;
}
void testCase() {
static int Case = 0;
int n;
scanf("%d%u%u%u", &n, &x, &y, &z);
for (int i = 0 ; i < n ; ++ i) {
a[i] = tang();
}
int m = max(0 , n - 100);
nth_element(a , a + m , a + n);
unsigned long long ans = 0;
for (int i = m ; i < n ; ++ i) {
for (int j = i + 1 ; j < n ; ++ j) {
ans = max(ans , 1ull * a[i] / __gcd(a[i] , a[j]) * a[j]);
}
}
printf("Case #%d: %llu\n", ++ Case, ans);
}
int main() {
int t;
scanf("%d", &t);
while (t --) {
testCase();
}
return 0;
}