奇迹银桥「1」
每次写三个需要奇迹银桥的题,不满三个不发
也许有人能拿这些搞事?(模拟赛?)
我会粘题面的
T1「LOJ#4」Quine
内存限制:256 MiB 时间限制:1000 ms
标准输入输出 题目类型:传统
评测方式:Special Judge
题目描述
输入格式
输出格式
题解
这个题,猛地一看,简单啊,cout
但是你仔细想想。
你要把源代码输出,莫非要递归? cout<<"cout<<"cout<<...."" 这显然是不行的。
所以要想办法打断递归。
窟思冥想。
可以用 printf ,有 "%s" 可以用,就是我们可以保证一个%s就可以输出一层了,然后就停下了。
信心满满的去码了。
然后,发现第二个问题:
在C++中,一个"\n"代表换行,一个"\""代表双引号,而只有"\\"才代表一个反斜杠。
(一个\要用\\输出,用\\又有用\\\\输出……)
又炸了。
再次去规避这些问题。
打一个表出来:
| " | 34 |
| '\n' | 10 |
好了,我们应该可以切了这个题了。
用%c输出10,34来换行,加引号。
但还是要避免换行,减少码长。
#include<cstdio>
int main(){char s[]="#include<cstdio>%cint main(){char s[]=%c%s%c;printf(s,10,34,s,34);}";printf(s,10,34,s,34);}
T2 排座椅
题目描述
输入格式
输出格式
样例
题解
这个题很简单,只是说一个其基因桥,用小数点存一些相关信息
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
float tcl[2001]={0};
float tch[2001]={0};
void pour(float a[],int b){
for(int i=1;i<=b;i++){
cout<<a[i]<<" ";
}
cout<<"\n";
}
int main(){
int h,l,cuh,cul,cdn;
int ch1,cl1,ch2,cl2;
cin>>l>>h>>cuh>>cul>>cdn;
for(int i=1;i<=cdn;i++){
cin>>cl1>>ch1>>cl2>>ch2;
if(ch1==ch2){
tch[cl1<=cl2?cl1:cl2]++;
// pour(tcl,l);
}
if(cl1==cl2){
tcl[ch1<=ch2?ch1:ch2]++;
// pour(tch,h);
}
}
for(int i=1;i<=l;i++){
if(tcl[i]!=0) tcl[i]+=(float)i/10000;
else tcl[i]=0;
// pour(tcl,l);
// cout<<" l"<<tcl[i]<<endl;
}
for(int j=1;j<=h;j++)
{
if(tch[j]!=0) tch[j]+=(float)j/10000;
else tch[j]=0;
// pour(tch,h);
}
sort(tcl+1,tcl+l+1,greater<float>());
// pour(tcl,l);
sort(tch+1,tch+h+1,greater<float>());
// pour(tch,h);
int r;
for(int i=1;i<=h;i++){
if(tch[i]<=0){
tch[i]=1001.1;
continue;
}
r=(int)tch[i];
tch[i]=(tch[i]-r)*10000;
}
for(int i=1;i<=l;i++){
if(tcl[i]<=0){
tcl[i]=1001.1;
continue;
}
r=(int)tcl[i];
tcl[i]=(tcl[i]-r)*10000;
}
sort(tcl+0,tcl+cul+1,less<float>());
sort(tch+0,tch+cuh+1,less<float>());
// pour(tch,h);pour(tcl,l);
for(int i=1;i<=cuh;i++){
//cout<<"r"<<r<<endl;
/* if(r<1000)*/printf("%.0f",tch[i]);
//cout<<"l"<<tcl[i]<<endl;
if(i==cuh){
printf("\n");
break;
}
else printf(" ");
}
for(int i=1;i<=cul;i++){
//cout<<"r"<<r<<endl;
/* if(r<1000)*/printf("%.0f",tcl[i]);
// cout<<(tch[i]-r)*1000;
if(i==cul){
printf("\n");
break;
}
else printf(" ");
}
getchar();
return 0;
}
T3 [LOJ#3]Copycat
题目描述
这道题用于测试文件输入输出,请注意使用文件输入输出,而非标准输入输出。
输入一个正整数$a$,输出这个数$a$
输入格式
第一行一个正整数$T$,表示有$T$组测试数据。
接下来$T$行,每行一个正整数$a$.
输出格式
输出$T$行,每行一个正整数$a$。
样例
题解
这不是题解,是比较一下各种文件输入输出的速度哒!

最上面是:fopen
#include <cstdio>
char st[99999];
int main() {
FILE *fin, *fout;
fin = fopen("copycat.in", "rb");
fout = fopen("copycat.out", "wb");
int num;
fscanf(fin, "%d", &num);
for (int i = 1; i <= num; i++) {
fscanf(fin, "%s", st);
fprintf(fout, "%s\n", st);
}
fclose(fin), fclose(fout);
return 0;
}
中间是:fstream(我喜欢流输入输出)
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
using namespace std;
int T;
string a;
int main() {
fstream fin, fout;
fin.open("copycat.in", ios_base::in);
fout.open("copycat.out", ios_base::out);
fin >> T;
while (T--) {
fin >> a;
fout << a << endl;
}
fin.close();
fout.close();
return 0;
}
最下面是:freopen(简单)
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
using namespace std;
int T;
string a;
int main() {
freopen("copycat.in", "r", stdin);
freopen("copycat.out", "w", stdout);
cin >> T;
while (T--) {
cin >> a;
cout << a << endl;
}
fclose(stdin), fclose(stdout);
return 0;
}
终于水完了
这是第一弹的全部内容!
Miemeng真的蒻

浙公网安备 33010602011771号