This commit is contained in:
Zengtudor 2024-10-21 20:22:23 +08:00
parent 93c7ee4776
commit 12ab34e7a4
2 changed files with 131 additions and 2 deletions

View File

@ -19,16 +19,33 @@ int main(){
std::cin>>s;
ll odd_add_num{}; //奇数+ -> -2
ll even_sub_num{};//偶数- -> +2
/*
->(bin*1)
->(bin*0)
->
+1
-1
->
->
'+'
(*1)->xor 1->*0 -2
(*0)->xor 1->*1 0
'-'
(*1)->xor 1->*0 0
(*0)->xor 1->*1 +2
*/
ll sum{};
for(ll i{0};i<s.size();i++){
if(s[i]=='+'){
if(i&1){
if(i&1){//奇数
++odd_add_num;
}
sum++;
}else{
if((i&1)==0){
if((i&1)==0){ // 偶数
even_sub_num++;
}
sum--;

112
src/P1351/P1351.cpp Normal file
View File

@ -0,0 +1,112 @@
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using ll = long long;
const ll max_n = 2e5+5;
const ll MOD = 10007;
ll n, w[max_n];
std::vector<ll> next[max_n];
ll brothers_from_father[max_n];
ll ans_max,ans_sum;
#ifdef ONLINE_JUDGE
#define DEBUG(code)
#else
#define DEBUG(code)code
#endif
DEBUG(
template<class ...Args>
void debug(Args&&...args){
std::cout<<"[DEBUG]: ";
(std::cout<<...<<std::forward<Args>(args));
std::cout<<'\n';
}
)
void dfs(const ll now, const ll father,const ll grand_father){
if(father == -1){
for(const auto i:next[now]){
if(i==father)continue;
dfs(i, now,-1);
}
return;
}else if(grand_father == -1){
for(const auto i:next[now]){
if(i==father)continue;
dfs(i,now,father);
}
return;
}
DEBUG(
debug("args: ",now," ",father," ",grand_father);
)
if(!next[now].empty()){
for (const auto i: next[now]) {
if(i==father)continue;
dfs(i,now,father);
}
}
for(const auto i : next[father]){
if(i != now){
ans_max = std::max(ans_max, w[i]*w[now]);
DEBUG(
debug("update max ",ans_max);
)
DEBUG(
debug("brother: ",w[i],' ',w[now]);
)
brothers_from_father[father] = ((w[i]*w[now]) % MOD + brothers_from_father[father]) % MOD;
}
}
DEBUG(
debug(w[now],' ',w[grand_father]);
)
ans_max = std::max(ans_max, w[now] * w[grand_father]);
DEBUG(
debug("update max ",ans_max);
)
ans_sum = (ans_sum + (w[now]*w[grand_father]) % MOD) % MOD;
}
int main(){
std::cin>>n;
for(ll i{1};i<n;i++){
ll a,b;
std::cin>>a>>b;
next[a].push_back(b);
next[b].push_back(a);
}
for(ll i{1};i<=n;i++){
std::cin>>w[i];
}
dfs(1, -1, -1);
for(ll i{1};i<=n;i++){
DEBUG(
debug("from brother ",i," add :",brothers_from_father[i]);
)
ans_sum = (ans_sum + brothers_from_father[i]) % MOD;
}
std::cout<<ans_max<<' '<<(ans_sum) % MOD<<'\n';
}
/*
4
1 2
2 3
2 4
1 2 3 4
(3,4),(4,3),(1,3),(3,1),(1,4),(4,1)
max = 12
sum = 12+12+3+3+4+4 = 38
*/