社区讨论
一个很奇怪的问题
学术版参与者 4已保存回复 8
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 8 条
- 当前快照
- 1 份
- 快照标识符
- @mjf3vkvb
- 此快照首次捕获于
- 2025/12/21 10:26 2 个月前
- 此快照最后确认于
- 2025/12/23 17:10 2 个月前
rt。
就是我在弄查整活机(上面那份代码)的时候,它读取到了 ZJ-S00371 的 club 题的代码,读到一半,屏幕输出一个问号,然后剩下的字符全都被吃了,但 printf 能正常输出;后面我尝试加了 cout.clear(),就好了!
虽然问题解决了,但是不知道为什么。有大佬能解答吗?
没有 ios 或者 cin/cout.tie。
这是该人代码(我不确定在洛谷上放一下会不会就复现不了):
CPP#include <bits/stdc++.h>
using namespace std;
//~ #define calc_time
namespace zyc{
#define pb push_back
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
const int N=1e5+10;
int n,a[5],sum,id[5];
bool cmp(int x,int y){return a[x]>a[y];}
vector<int>g[5];
void run(){
sum=0;
rep(i,1,3)g[i].clear();
cin>>n;
rep(i,1,n){
rep(j,1,3)cin>>a[j],id[j]=j;
sort(id+1,id+4,cmp);
sum+=a[id[1]];
g[id[1]].pb(a[id[1]]-a[id[2]]);
}
if((int)g[2].size()>n/2)swap(g[1],g[2]);
if((int)g[3].size()>n/2)swap(g[1],g[3]);
if((int)g[1].size()>n/2){
sort(g[1].begin(),g[1].end());
n=g[1].size()-n/2;
per(i,n-1,0)sum-=g[1][i];
}
cout<<sum<<'\n';
}
int main(){
#ifdef calc_time
auto S=clock();
#endif
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen("club.in","r",stdin);
freopen("club.out","w",stdout);
int T;cin>>T;
while(T--)run();
#ifdef calc_time
auto E=clock();
double D=double(E-S)/CLOCKS_PER_SEC*1000;
cerr<<D<<" ms\n";
#endif
return 0;
}
}
int main(){return zyc::main();}
//Ren5Jie4Di4Ling5%
//先把所有人分到最满意的部门
//然后对于“多于 n/2” 人的部门
//我们要找到最小的满意度差的前(多处的人的个数)个人 分到另一部门
//先从没有正确性的可能方案开始
//找到和第二志愿差最小的人,全部移动到第二志愿,这时如果还不符合条件,对那个组再这样操作
//看看特殊性质
//AB 都好做
//思考一个问题:先按照最大满意度分配完后,一定不可能出现两个组间交换成员的情况
//一旦交换,那么不仅人数调整没有贡献,总满意度必然不增
//这是一个很妙的发现
//好吧其实我唐了
//一旦有一个组人数过半,把多出来的人分到别的组,别的组人数一定不会过半
//唉我反应真慢
复现不了可能需要去下一下
网址:https://www.qsnkj.org.cn/#/report/detail/20251101200359039
密码:#ozcxkfcT2ps!T.C
主要看 ZJ-00371 的 club 题。
密码:#ozcxkfcT2ps!T.C
主要看 ZJ-00371 的 club 题。
查整活机代码:
Info
大部分都没用,问题主要在九十一到九十四行(复制到 DEVC++ 后的第九十一到九十四行)。
CPP#include<io.h>
#include<vector>
#include<conio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<windows.h>
using namespace std;
#define int long long
const int N=3000,P=998244353;
const int PERSON=2049; //这个省的人数
const bool STOP_FOR_UNFINDEDPERSON=1; //显示缺考学生
const bool STOP_FOR_UNFINDEDFILE=0; //显示未提交代码
const bool STOP_FOR_BIGCODE=0; //显示大文件
const bool STOP_FOR_HUGECODE=1; //显示超大文件
const bool STOP_FOR_IMPORTANTWODR=0; //显示关键词
const bool STOP_FOR_UNCHINESE=0; //显示非汉字注释
const int HUGE_CODE=3600; //大文件标准
const int WORD_SUM=25; //关键词个数
string test[]={"club","road","replace","employ"}; //这是题目名
string word[]={".ans","bits\\stdc++.h","ccf","#include<windows.h>","fuck","mian","slove","kkksc03","luogu","chenzhe","csp","chen_zhe","afo","feropen","never gonna give you up","\"r\",stdout","\"w\",stdin","AFO","CCF","€€£","//freopen","uid","UID","RP++","rp++"};
int jump=0,cont[N][5][WORD_SUM+5];
char name[N];
int CtrlV(string s){
memset(name,0,sizeof(name));
int n=0;
for(int i=0;i<s.size();i++)
name[i]=s[i];
return n;
}
bool FLG;
string NAME;
void Write(){
if(FLG) return;
FLG=1;
cout<<NAME<<endl<<endl;
}
void check(string s,int x,int y){
for(int i=0;i<WORD_SUM;i++){
int p=0;
cont[x][y][i]=0;
while(p<s.size()){
p=s.find(word[i],p);
if(p>=s.size()) break;
cont[x][y][i]++;
p++;
}
}
}
string read(){
char c;
string code;
while(1){
c=getchar();
if(c==EOF) break;
code+=c;
}
return code;
}
int slove(int ck1,int ck2){
char c;
string code=read();
//cout<<code<<endl<<endl<<endl<<endl;
check(code,ck1,ck2);
bool zs=0,zs2=0,wt=0,hz=0;
if(code.size()>HUGE_CODE){
if(code.size()>10*HUGE_CODE){
if(STOP_FOR_HUGECODE){
Write();
wt=1;
cout<<"超大文件,代码长度:"<<code.size()<<endl;
}
}
else{
if(STOP_FOR_BIGCODE){
Write();
wt=1;
cout<<"大文件,代码长度:"<<code.size()<<endl;
}
}
}
code=' '+code;
for(int i=0;i<code.size();i++){
if((int)(code[i])<0){
wt=1,hz=1,Write();
break;
}
}
if(hz||STOP_FOR_UNCHINESE){
for(int i=0;i<code.size();i++){
//cout<<code[i]<<' ';
//printf(" ");
if(zs||zs2) cout<<code[i]; //问题在这
cout.clear(); //这就是那个 cout.clear()
if(code[i]=='/'&&code[i-1]=='/'){
if(!zs){
Write();
cout<<"//";
}
zs=1,wt=1;
}
if(code[i]=='/'&&code[i-1]=='*'&&zs==0){
if(zs2) cout<<endl<<endl;
zs2=0;
}
if(i+2<code.size()&&code[i+1]=='/'&&code[i+2]=='*'&&zs==0){
Write();
zs2=1,wt=1;
}
if(code[i]=='\n'){
if(zs) cout<<endl;
zs=0;
}
}
}
if(STOP_FOR_IMPORTANTWODR){
bool flg=0;
for(int k=0;k<WORD_SUM;k++){
if(cont[ck1][ck2][k])
flg=1;
}
if(flg){
Write();
wt=1;
}
for(int k=0;k<WORD_SUM;k++){
if(cont[ck1][ck2][k])
cout<<word[k]<<"出现了"<<cont[ck1][ck2][k]<<"次\n";
}
cout<<endl;
}
if(wt==0){
system("cls");
return 0;
}
cout<<"\n代码长度:"<<code.size()-1<<endl;
//start "" "notepad" "C:\Users\学生\Desktop\元旦计时.cpp"
while(1){
if(GetAsyncKeyState('P')){
Sleep(100);
system("cls");
return 0;
}
if(GetAsyncKeyState('O')){
Sleep(100);
system("cls");
return 1;
}
if(GetAsyncKeyState('B')){
Sleep(100);
system("cls");
return 2;
}
}
}
int ans[N];
int ufpson[N];
signed main(){
string s1="C:\\Users\\15020\\Desktop\\"; //这是全省代码的文件夹所在的位置
string s2="ZJS"; //这是全省代码的文件夹名
string s3="ZJ-S"; //这是每份代码文件夹除考号外的其他信息
int ufperson=0,ufcode=0,lt=0;
for(int i=370;i<=PERSON;i++){
if(jump){
int at=i*100/PERSON;
if(at!=lt){
system("cls");
cout<<at<<"%\n";
lt=at;
}
}
string nam;
nam=s1+s2+"\\"+s3;
int p=i;
string t;
while(p){
t=char(p%10+'0')+t;
p/=10;
}
while(t.size()<5) t='0'+t;
nam+=t;
CtrlV(nam);
if(_access(name,0)){
ufperson++;
ufpson[ufperson]=i;
if(STOP_FOR_UNFINDEDPERSON){
if(jump==0) cout<<nam<<":未查询到该选手文件夹\n";
while(GetAsyncKeyState('P')==0&&jump==0);
Sleep(100);
if(jump==0) system("cls");
}
continue;
}
nam+="\\";
for(int j=0;j<4;j++){
CAT:
FLG=0;
string nam2=nam+test[j]+"\\"+test[j]+".cpp";
NAME=nam2;
CtrlV(nam2);
char flg;
if(_access(name,0)){
ufcode++;
if(STOP_FOR_UNFINDEDFILE){
if(jump==0) cout<<"该选手无该题代码\n"<<endl;
while(GetAsyncKeyState('P')==0&&jump==0);
Sleep(100);
}
if(jump==0) system("cls");
continue;
}
cin.clear();
cout.clear();
freopen(name,"r",stdin);
//cout<<name<<endl;
int Flg=0;
if(jump){
string code=read();
check(code,i,j);
}
if(jump==0) Flg=slove(i,j);
for(int k=0;k<WORD_SUM;k++) ans[k]+=cont[i][j][k];
if(Flg==1){
string nam3=nam2;
nam2="start \"\" \"notepad\" \""+nam2+'"';
if(jump==0) cout<<nam2<<endl;
CtrlV(nam2);
cin.clear();
cout.clear();
system(name);
goto CAT;
}
if(Flg==2) jump=1;
}
}
system("cls");
cout<<"缺考学生:"<<ufperson<<endl;
for(int i=1;i<=ufperson;i++)
cout<<ufpson[i]<<endl;
cout<<endl;
cout<<"未查询到的代码:"<<ufcode<<endl;
cout<<"关键词:\n";
for(int i=0;i<WORD_SUM;i++){
cout<<word[i]<<':'<<ans[i]<<endl;
for(int j=1;j<=PERSON;j++){
for(int k=0;k<4;k++){
if(cont[j][k][i])
cout<<j<<" 号选手的"<<test[k]<<"题出现了 "<<cont[j][k][i]<<" 次\n";
}
}
cout<<endl<<endl;
}
return 0;
}
回复
共 8 条回复,欢迎继续交流。
正在加载回复...