Compare commits

...

3 Commits

Author SHA1 Message Date
Zengtudor
c0d1a2f156 feat: 添加P9980题解实现
实现P9980题目的解法,包括输入处理和矩阵运算逻辑。使用动态规划思想计算相邻节点关系,最终输出结果。
2025-09-30 19:32:24 +08:00
Zengtudor
9eba3f859a fix: 移除多余的std::cout语句
修复了在特定条件下出现的多余std::cout语句,该语句没有实际输出内容且可能导致不必要的性能开销
2025-09-30 16:56:21 +08:00
Zengtudor
250e0ca930 refactor: 移动并重写P8866.cpp文件
将P8866.cpp从src/8/12目录移动到src/9/29目录
重写文件内容,添加完整逻辑处理输入输出
2025-09-30 16:33:14 +08:00
3 changed files with 81 additions and 3 deletions

View File

@ -1,3 +0,0 @@
int main(){
}

42
src/9/29/P8866.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <cstdint>
#include <iostream>
using ll = int64_t;
ll T,n,m,k,kp;
int main(){
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin>>T;
while(T--){
std::cin>>n>>m>>k;
bool isn2n=false;
ll n2n=0;
for(ll i=1;i<=m;i++){
std::cin>>kp;
nxt:;
if(isn2n && kp!=2*n-1){
if((n2n&1)==0){
for(ll j=1;j<=n2n;j++){
std::cout<<1<<" "<<n<<"\n";
goto nxt;
}
}else{
if((kp&1)==0){
for(ll j=1;j<=n2n;j++){
std::cout<<1<<" "<<((kp+1)>>2)<<"\n";
}
}
}
isn2n=false;
n2n=0;
}else if(kp==2*n-1){
n2n++;
isn2n=true;
}
}
}
}

39
src/9/29/P9980.cpp Normal file
View File

@ -0,0 +1,39 @@
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <istream>
using ll = int64_t;
const ll maxn = 750+5;
ll n;
bool b[maxn][maxn],z[maxn][maxn];
char tmp;
ll ans;
int main(){
std::iostream::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin>>n;
for(ll i=1;i<n;i++){
for(ll j=i+1;j<=n;j++){
std::cin>>tmp;
b[i][j]=tmp-'0';
}
}
for(ll i=1;i<n;i++){
ans+=b[i][i+1];
z[i][i+1]=b[i][i+1];
}
for(ll i=1;i<=n-2;i++){
for(ll j=i+2;j<=n;j++){
bool zn=false;
for(ll k=i+1;k<j;k++){
zn^=z[i][k];
z[i][j]=zn^z[k][j];
ans+=z[i][j];
}
}
}
std::cout<<ans<<"\n";
}