freopen

USACO19JAN Gold题解

北慕城南 提交于 2019-11-30 17:53:30
噩梦的回忆。。 上周日在机房打的模拟赛,结果十分惨烈,就最后一题yy出了正解结果玄学的只拿了80 考试结果:0+0+80=80 订正时对着T3打了2hours结果还是90 订正结果:100+100+90=290 我太弱了QAQ T1 Luogu P5196 [USACO19JAN]Cow Poetry 题目链接 思路:dp+神奇的数学推导 快速幂一开始还写锅了,受到了ftq大佬的嘲笑 code #include<bits/stdc++.h> using namespace std; const int MOD=1e9+7,MAXN=5000+10; int f[5010][MAXN],s[MAXN],c[MAXN],g[MAXN],num[35],n,m,k; long long ans,re=1; long long pow(int b, int p) { if (p == 0) { return 1; } long long x = b; long long ans = 1; while (p > 0) { if (p % 2 == 1) { ans = ans * x % MOD; } x = x * x % MOD; p = p >> 1; } return ans % MOD; } void debug() { for(int i=1;i<=5;++i){ cout<<f

CodeForces - 35D

蓝咒 提交于 2019-11-30 00:35:41
题目: https://vjudge.net/contest/326867#problem/A 题意: 有一个农场,自己有m斤粮食,有n天,每天动物吃的量不同,那个动物的食量的是由他是从那天开始进这个农场确定的,后面不能再变,从这天进来后就必须吃到第n天,每天只能进来一个动物,问最后能被保留下来的动物数最大是多少 思路: 1.贪心+排序 ,既然他每天只能进入一个动物,而且动物进来后食量不变,而且进来知道吃多少天,那么相当于我们知道所有动物的消费粮食值是多少个,然后我们直接排序,选取最少的那几个即可 O(nlogn) #include<bits/stdc++.h> #define maxn 100005 #define mod 1000000007 using namespace std; typedef long long ll; ll a[maxn],n,m; int main(){ freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; a[i]=a[i]*(n-i+1); } sort(a+1,a+n+1); int num=0; for(int i=1;i<=n;i++){ if(m>=a[i]){ m-=a

Create a file if one doesn't exist - C

廉价感情. 提交于 2019-11-29 20:09:18
I want my program to open a file if it exists, or else create the file. I'm trying the following code but I'm getting a debug assertion at freopen.c. Would I be better off using fclose and then fopen immediately afterward? FILE *fptr; fptr = fopen("scores.dat", "rb+"); if(fptr == NULL) //if file does not exist, create it { freopen("scores.dat", "wb", fptr); } You typically have to do this in a single syscall, or else you will get a race condition. This will open for reading and writing, creating the file if necessary. FILE *fp = fopen("scores.dat", "ab+"); If you want to read it and then write

CJ 9.14 test

*爱你&永不变心* 提交于 2019-11-29 14:00:22
题面1JZMwl10Z1zyD7QxkSKpRfw evy3 10+20+100 本来能AK的,结果搞成这个鬼样子,真的气啊 Alice和Bob的游戏game 如果质因子个数为 \(2\) 就Bob胜,否则Alice胜,显然。 结论推错了直接100->10。 #include<bits/stdc++.h> #define LL long long using namespace std; int main() { freopen("game.in","r",stdin),freopen("game.out","w",stdout); int T,num;LL n,i; for(scanf("%d",&T);T;--T) { scanf("%lld",&n),num=0; for(i=2;i*i<=n;++i) if(n==1) break; else while(!(n%i)) n/=i,++num; if(n^1) ++num; puts(num^2? "Alice":"Bob"); } return 0; } 灭鲲kun 我们把鲲降序排序,把视频按 \(d\) 降序排序。 然后扫鲲,把所有能消灭它的视频放进一个优先队列,优先队列按 \(c\) 升序排序,然后把堆顶取出计算答案。 若堆空则无解。 \(m\) 打成$n$100->20。 #include<bits/stdc++.h

Using freopen() to print to file and screen

柔情痞子 提交于 2019-11-29 13:15:45
I am trying to use freopen() to print to a text file and the screen, but I am only achieving the printing to a file. I was wondering if there was an easy to save the programs output to a file and print it to the screen? Because I had this working another way, but I ended up having to print out every statement twice. One being for the file the other just for the output. Note: I am new to C++ and I am trying to learn it for a class next semester so direct answer are needed as I have already look online and couldn't find any simple answers to this solution besides. Here is what I have so far:

[NOI2011]兔兔与蛋蛋游戏

你说的曾经没有我的故事 提交于 2019-11-29 10:19:11
传送门 直接博弈论dfs可以得到75分 (然鹅我博弈论学的很pie) #include<bits/stdc++.h> #define LL long long #define INF 10000 using namespace std; int read() { int x=0,f=1;char s=getchar(); while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();} while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();} return x*f; } char s[45]; int lr[]={0,0,1,-1},ud[]={1,-1,0,0},ans[1003],tu[43][43],sg[43]; int X,Y,tot=0,n,m; int dfs(int x,int y,int op) { for(int i=0;i<4;++i) { int xx=x+ud[i],yy=y+lr[i]; if(xx<1||xx>n||yy<1||yy>m||tu[xx][yy]!=op)continue; swap(tu[xx][yy],tu[x][y]); if(!dfs(xx,yy,op^1)){swap(tu[xx][yy],tu[x][y]);return 1;}//往下递归得到每一个局面

Educational Codeforces Round 71

亡梦爱人 提交于 2019-11-29 06:41:22
https://www.cnblogs.com/31415926535x/p/11460682.html 上午没课,做一套题,,练一下手感和思维,, 教育场的71 ,,前两到没啥,,后面就做的磕磕巴巴的,,,有想法但是不敢实现,,自我否定,,没了思路就只能官方题解,,发现其实都很简单,,,思维场把,,,, A There Are Two Types Of Burgers 贪心就完事了,,推出公式不知道怎么证明是最优的,,,(敲错变量还wale一发emmm #include <bits/stdc++.h> #define aaa cout<<233<<endl; #define endl '\n' #define pb push_back using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; // mt19937 rnd(time(0)); const int inf = 0x3f3f3f3f;//1061109567 > 1e9 const ll linf = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-7; const double pi = 3.14159265358979; const int

2019暑假记录下

痞子三分冷 提交于 2019-11-29 01:34:01
8.26 Day1   爆零祭,跑8圈预定祭,被Tham D祭   T1 书堆(a)   题意:bzoj 2048   题解:可看出 \(ans=m* \sum_{i=1}^{n}{\frac{1}{2i}}\) (虽然我这个物理菜狗并没有看出来)   然后有一个玄学的调和级数近似公式    \[\sum_{i=1}^{n}{\frac{1}{i}}=\ln(n)+\gamma\]   其中 \(\gamma\) 为欧拉常数,约等于 \(0.57721566\) (背了就行)   注意这只是一个近似公式   复杂度 \(O(1)\sim O(n)\) #include<bits/stdc++.h> using namespace std; int main() { freopen("a.in","r",stdin); freopen("a.out","w",stdout); long long n,m,ans; long double f=0; scanf("%lld%lld",&n,&m); if(n<=1e7) for(int i=2;i<=n<<1;i+=2) f+=1.0/i; else f=(log(n)+0.5772156649)/2; ans=f*m-1e-6; printf("%lld\n",ans); return 0; }   T2 最长距离 b   题意

JLOI2011 飞行路线

三世轮回 提交于 2019-11-29 00:51:59
洛谷 BZOJ 分析 经典的分层最短路题(我不会)。 建 \(k+1\) 层图,跑一遍最短路,找到 \(dis[i]\) 最小的一个。 代码 #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define il inline #define re register #define INF 0x3f3f3f3f #define tie0 cin.tie(0),cout.tie(0) #define fastio ios::sync_with_stdio(false) #define File(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout) using namespace std; typedef long long ll; template <typename T> inline void read(T &x) { T f = 1; x = 0; char c; for (c = getchar(); !isdigit(c); c = getchar()) if (c == '-') f = -1; for ( ; isdigit(c); c = getchar()) x = x

# NK 0827 练习赛 反思

久未见 提交于 2019-11-28 21:48:24
NK 0827 练习赛 反思 小小总结 期望得分 200 实际得分 210 还算可以的啦 但还是要继续加油 要稳住不要翻车的啊 A 异或 题面描述 何老板给你一个长度为 \(N\) 的整数数列 。 请你帮他找出满足下列条件的数字对 \([l,r]\) 的个数: \(a_l\) ^ \(a_{l+1}\) ^ \(a_{l+2}\) ... \(a_r\) = \(a_l\) + \(a_{l+1}\) + \(a_{l+2}\) ... \(a_r\) " \(xor\) "表示“异或”,对应c++中的符号是"^" 输入格式 第一行,一个整数 第二行, 个空格间隔的整数 输出格式 一个整数,表示满足条件的数字对的个数 解: 双指针的裸题 首先异或被称为"不进位的加法" 那么区间就满足单调性 所以我们可以用双指针 每次右指针扩展 然后左边指针移动到合法位置 中间的都行 code: // #include<bits/stdc++.h> using namespace std; #define ll long long ll sum; ll n; #define maxnn 400000 ll a[maxnn]; ll tot=0; int main() { // freopen("axor.in","r",stdin); //freopen("axor.out","w",stdout)