freopen

CSP-J 2019SC 0分原因分析

时光怂恿深爱的人放手 提交于 2019-12-06 15:02:13
首先说一下正确使用freopen的方式 /*将 <题目cpp文件名> 替换为cpp文件名 freopen("<题目cpp文件名>.in", "r", stdin); freopen("<题目cpp文件名>.out", "w", stdout); */ //number.cpp #include<bits/stdc++.h> using namespace std; int main() { freopen("number.in", "r", stdin); freopen("number.out", "w", stdout); // 以下开始解题代码 . . . . . . fclose(stdin); //本行不是必须 fclose(stdout); //本行不是必须 return 0; } 错误实例 绝大部分来自于SC CSP-J的代码 没有代码的 存错目录了,存错盘符等没有按要求放cpp文件的 四川没有代码的, SC-Junior @SC ntotal 793, lost 16: SC-00033 SC-00060 SC-00110 SC-00112 SC-00123 SC-00131 SC-00153 SC-00185 SC-00227 SC-00308 SC-00381 SC-00387 SC-00432 SC-00561 SC-00715 SC-00781 SC

C文件操作

混江龙づ霸主 提交于 2019-12-06 07:06:54
文件操作步骤: 1、创建文件指针 2、关联文件 3、操作文件 4、关闭文件 question: 求文件中数字的最大值、最小值、平均值 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <limits.h> 4 5 int main() 6 { 7 int x, n=0, sum=0; 8 int min=INT_MAX, max=INT_MIN;//click this link 9 FILE *fin, *fout;//1、创建文件指针 10 11 //2、关联文件 12 fin = fopen("data.in", "r"); 13 fout = fopen("data.out", "w"); 14 15 //3、操作文件 16 while(fscanf(fin, "%d", &x) == 1){ 17 sum += x; 18 if(x<min) min=x; 19 if(x>max) max=x; 20 n++; 21 } 22 23 fprintf(fout, "min=%d\nmax=%d\navg=%.3lf\n", 24 min, max, (double)sum/n); 25 26 //关闭文件 27 fclose(fin); 28 fclose(fout); 29 30 return 0; 31 } 补充

Codeforces Round #603 (Div. 2)

我的未来我决定 提交于 2019-12-06 04:22:46
A. Sweet Problem 题目大意:你有不同数量的红绿蓝三种颜色的糖果,每天想吃两颗颜色不同的糖果,问能吃多少天。 2019ICPC沈阳赛区flowers的弱化题qwqflowers是有n种花选m种不同种类的一朵花组成一束花问最多能组成多少束。 是否可行具有单调性,二分天数,只要选的糖果数小于等于天数,就一定存在某种方案,不会出现某一天吃两只同样的糖果。 1 #include <bits/stdc++.h> 2 #define MIN(a,b) ((((a)<(b)?(a):(b)))) 3 #define MAX(a,b) ((((a)>(b)?(a):(b)))) 4 #define ABS(a) ((((a)>0?(a):-(a)))) 5 using namespace std; 6 7 template <typename T> 8 void read(T &x) { 9 int s = 0, c = getchar(); 10 x = 0; 11 while (isspace(c)) c = getchar(); 12 if (c == 45) s = 1, c = getchar(); 13 while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); 14 if (s) x =

How to write in stdout after using freopen [duplicate]

泄露秘密 提交于 2019-12-06 04:10:34
This question already has answers here : How to redirect the output back to the screen after freopen(“out.txt”, “a”, stdout) (6 answers) Closed 5 years ago . After freopen -ing stdout , How can I print on terminal? freopen("out", "w", stdout); // reopen stdout /* something */ printf("Now I want to print this on terminal"); P.P. I believe this is what you are looking for: Once I've used freopen, how can I get the original stdout (or stdin) back? There's no portable solution. But the link also explains a possible solution using your own stream and a non-portable solution that'll work on most

AtCoder-arc058(题解)

£可爱£侵袭症+ 提交于 2019-12-05 17:44:49
A - こだわり者いろはちゃん / Iroha's Obsession(暴力) 题目链接 题目大意: 给你 \(k\) 个个位数字和一个数字 \(n\) ,要求找到一个大于等于n的数字,使得不出现 \(k\) 个数. 大致思路: 直接枚举就行了,最多枚举到多一位。 代码: #include<bits/stdc++.h> using namespace std; int n,k; int vis[20]; bool check(int x){ while(x){ int d=x%10; x/=10; if(vis[d])return 0; } return 1; } int main() { //freopen("H:\\c++1\\in.txt","r",stdin); //freopen("H:\\c++1\\out.txt","w",stdout); scanf("%d%d",&n,&k); for(int i=1,x;i<=k;i++)scanf("%d",&x),vis[x]=1; for(int i=n;;i++){ if(check(i)){ printf("%d\n",i);return 0; } } return 0; } B - いろはちゃんとマス目 / Iroha and a Grid(组合数) 题目链接 题意大意: 一个 \(H\) 和 \(W\)

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3)

女生的网名这么多〃 提交于 2019-12-05 12:13:30
A.Math Problem(CF 1262 A) 题目大意:给定n条线段,求一条线段,使得这个线段能够跟所有给定的线段都相交(端点值一样也算相交),最小化它的长度,可以是0. 很显然找出这n条线段的左端点最大值和右端点的最小值,它们的差和0的最大值即为答案。 1 #include <bits/stdc++.h> 2 #define MIN(a,b) (((a)<(b)?(a):(b))) 3 #define MAX(a,b) (((a)>(b)?(a):(b))) 4 using namespace std; 5 6 template <typename T> 7 void read(T &x) { 8 int s = 0, c = getchar(); 9 x = 0; 10 while (isspace(c)) c = getchar(); 11 if (c == 45) s = 1, c = getchar(); 12 while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); 13 if (s) x = -x; 14 } 15 16 template <typename T> 17 void write(T x, char c = ' ') { 18 int b[40], l = 0; 19

codeforces - 1253 (div2)

◇◆丶佛笑我妖孽 提交于 2019-12-05 00:06:19
A - Single Push if 、 else 特判 #include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #pragma GCC optimize(2) #define mm(i,v) memset(i,v,sizeof i); #define mp(a, b) make_pair(a, b) #define one first #define two second using namespace std; typedef long long ll; typedef pair<int, int > PII; const int N = 1e5 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f; int t, n, idx; int a[N], b[N]; int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // cin.tie(0); // cout.tie(0); // ios::sync_with_stdio(0); cin >> t

Trying to create an output file with freopen, using non-constant string

左心房为你撑大大i 提交于 2019-12-04 21:52:31
I'm trying to create a file whose name is a string constant, but a string consisting of a constant string "List" an integer + + an extension. Here's my code: #include <iostream> #include <vector> #include <iostream> #include <fstream> #include <iomanip> #include <string> using namespace std; int main (){ int cont=0; std::string result; std::string name = "Lista"; std::string ext = ".txt"; char numstr[21]; // enough to hold all numbers up to 64-bits sprintf(numstr, "%d", cont); result = name + numstr+ext; freopen (result, "w", stdout); cout<<result<<endl; return 0; } When I try to build tells

Educational Codeforces Round 76 (Rated for Div. 2)

*爱你&永不变心* 提交于 2019-12-04 14:24:50
Educational Codeforces Round 76 (Rated for Div. 2) A: Two Rival Students 水题,找距离最远,特判已经到达端点情况即可 B: Magic Stick 分析 ​ 最开始想是暴力覆盖整个区间,但1e9很显然不可能,分析样例,盲猜只有以下情况是NO ((a==2 || a==3) && b!=3 && b!=2 && b!=1) (a==1 && b!=1) 事实证明是正确的,因为操作中有-1这种微调操作,基本除了小数据会是no其他都是yes 代码 #include <bits/stdc++.h> using namespace std; int main(){ //freopen("test.in","r",stdin); //freopen("test.out","w",stdout); int T,b,a; cin>>T; while(T--){ scanf("%d %d",&a,&b); if(a==1 && b!=1){printf("NO\n");continue;} else if((a==2 || a==3) && b!=3 && b!=2 && b!=1){printf("NO\n");continue;} else {printf("YES\n");continue;} } return 0; }

数学总结

故事扮演 提交于 2019-12-04 13:28:34
①乘法逆元 #include<iostream> #include<cstring> #include<cstdio> using namespace std; #define e exit(0) #define re register #define LL long long LL n,M; inline LL fd(){ LL s=1,t=0;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')s=-1;c=getchar();} while(c>='0'&&c<='9'){t=t*10+c-'0';c=getchar();} return s*t; } inline LL qsm(LL x,LL y){ LL base = 1; while(y){ if(y&1) base = (1ll*base%M*x%M)%M; x = (x%M*x%M)%M; y>>=1; } return base; } int main() { freopen("P3811.in","r",stdin); freopen("P3811.out","w",stdout); n = fd(),M = fd(); for(re LL i=1;i<=n;++i) printf("%lld\n",(qsm(i,M-2)%M+M)%M); return 0; }