getchar

电路图题解

和自甴很熟 提交于 2020-02-08 13:18:22
OJ 1177 1178 1179 一.电路图A 第一问,容易看出$右拐次数=左拐次数+4$,$左拐+右拐=n$,所以$右拐=n/2-2$,相当于$C_{n}^{n/2-2}$ 第二问,总个数除去最左端,最右端,最上方,最下方的电阻,整个电路被分成$4$段,每一段都有偶数个电阻,答案就是将$n$分成$4$个偶数的情况,相当于将$n/2$分成任意数的情况,用隔板法,答案就是$C_{n/2-1}^{3}$,排除旋转的影响,答案还要除以$4$。 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <deque> #include <string> using namespace std; inline long long read(){ long long ans = 0, f = 1; char ch = getchar(); while(!isdigit(ch)) f *= (ch == '-') ? -1 : 1, ch = getchar(); do ans = (ans << 1) + (ans << 3) + (ch ^ 48), ch = getchar(); while(isdigit(ch)); return ans * f; } const int

c/c++

*爱你&永不变心* 提交于 2020-02-08 06:23:33
#c/c++ #####头文件 stdio.h c语言的标准输入输出,常用 printf;scanf iostream c++语言的标准输入输出,重用 cin;cout algorithm c++的常用算法头文件,如 sort;qsort #####数组处理 memcpy 数组a复制k个元素到数组b: memcpy(b,a,sizeof(int)*k); 数组a全部复制到数组b: memcpy(b,a,sizeof(a)); memset 数组a清0:``` memset(a,0,sizeof(a)); > >这里注意一点,memset对int数组赋初值时**只能赋值0**,其他数都不能赋值,++因为memset赋值的单位是字节,而int是4个字节,所以你赋值0,每字节都是0.所以合起来4个字节也是0,但是赋值其他的数,4个字节合起来就不是原来的数了++。(所以memset大多用来给char数组赋初值,因为char是一个字节) * #####数学计算 + pow >```pow(double a,double b);``` >头文件:```<math.h>``` > 功能:计算a的b次方 * #####字符处理 + sprintf >printf输出到屏幕,fprintf输出到文件,sprintf输出到字符串 >```sprintf(a,"%d%d%d",a,b,c); ```/

20190708三人开黑CF模拟赛

こ雲淡風輕ζ 提交于 2020-02-07 22:34:30
7月8号晚上8点和两位巨佬开了一场虚拟cf: [ Helvetic Coding Contest 2018 online mirror (teams allowed, unrated) ] 我这么 蔡 ,只AC了A2、C1、C2、E1(被巨佬吊打) 我就说一下我写的几道题吧: A2. Death Stars (medium) The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the solar system that contains the Death Star. However, this time the Empire has hidden the Death Star very well, and

20190710双人开黑CF模拟赛

只谈情不闲聊 提交于 2020-02-07 22:07:45
Codeforces Round #571 (Div. 2) 日常被tanao_大佬带飞,我AC了A和C(B题没了。。。否则tanao_大佬肯定把我吊打) A. Vus the Cossack and a Contest Vus the Cossack holds a programming competition, in which \(n\) people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly \(m\) pens and \(k\) notebooks. Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook. Input The first line contains three integers \(n\) , \(m\) , and \(k\) (1≤n,m,k≤100) — the number of participants, the number of pens, and the number of notebooks

20180715 考试记录

▼魔方 西西 提交于 2020-02-07 06:40:53
T1 方程的解 Solution exgcd求ax+by=c 设方程 \(a'x+b'y=c'\) 其中 \(a'=a/(a,b)\) ; \(b'=b/(a,b)\) ; \(c'=c/(a,b)\) 我们能求出 \(ax'+by'=(a,b)\) 的一解 那么因为有 \(x=x'*c'\) 和 \(y=y'*c'\) 便可以求出设方程的一解(这也是原方程ax+by=c的一解) 由于 \(a'(x+t*b')+b'(x-t*a')=c'\) 当t取整数时均成立 那么可以利用 \(b'\) 求出x的最小整数值,然后求出最大y值 然后用最大y值与最小y值的关系求解的个数 PS:这个题还需要一堆特判,特判不对也可致凉 Code //By Menteur_Hxy #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #define F(i,a,b) for(register int i=(a);i<=(b);i++) #define R(i,a,b) for(register int i=(b);i>=(a);i--) using namespace std; typedef long long LL; LL rd() { LL x=0,f=1; char c

hdu入门搜索题

痴心易碎 提交于 2020-02-07 06:09:09
新人们加油,就优先队列有点难度,其它对新手很有学习价值 下面是我今晚刚刚刷的几道基本搜索题 hdu 1010 Tempter of the Bone 经典搜索入门题,DFS,本题考查要点:剪枝,奇偶性剪枝 View Code #include<stdio.h> #include<stdlib.h> int m,n,t; char map[8][8]; int dir[4][2]={{1,0},{-1,0},{0,-1},{0,1}}; int ex,ey,sx,sy,ok;//e表示end,终点,s表示start,出发点,ok用来判断是否在规定时间到达 void dfs(int x,int y,int cnt) { int i; if(cnt==t)//剪枝1:到时间了符合条件ok=1再退出,不符合条件直接退出。 { if(ex==x&&ey==y)ok=1; return; } if(ok)return;//找到解后还有部分在继续搜索,这条是为了让其它搜索停止 int temp=abs(x-ex)+abs(y-ey)-abs(cnt-t);//剪枝2:((((要点)))) //奇偶性剪枝 ,起点和终点确定以后就可以确定走的步数是奇数还是偶数,通过这个特点来剪枝 if(temp>0||temp&1)return;//temp&1相当于temp%2,运算位。 for(i=0;i<4

2020牛客寒假算法基础集训营2

这一生的挚爱 提交于 2020-02-07 00:44:34
我这么写会不会侵权...毕竟这是收钱的比赛 F.拿物品 题解 一开始理解错了,以为每个人只是取当前最大的就行,后来发现不对,我取了这个物品,获得 \(a_i\) ,不取走获得 \(-b_i\) ,所以就按照 \(a+b\) 排序然后按大小选就行 #include<iostream> #include<algorithm> #include<cmath> #include<cstdio> #include<cstring> #include<cstdlib> #include<queue> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) typedef long long LL; typedef pair<int,int> PII; #define X first #define Y second inline int read() { int x=0,f=1;char c=getchar(); while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} while(isdigit(c)){x=x*10+c-'0';c=getchar();} return x*f; } const int maxn=200010; int n,a[maxn],b[maxn],has[maxn]

2019-2020nowcoder牛客寒假基础2

余生长醉 提交于 2020-02-06 22:08:55
12点四十起床饭都没恰,温州阴郁的天气隐隐暗示了今天的基调 https://ac.nowcoder.com/acm/contest/3003#question A.做游戏 石头剪刀布wa两发娱乐一下,int的read加起来的时候在右边炸了一回,重新写sclll没抄对,甚至样例都没过就直接上了,这脑残的行径能怪谁呢 #include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <queue> #include <set> #include <map> #include <stack> using namespace std; #define scd(a) scanf("%d",&a) #define scdd(a,b) scanf("%d%d",&a,&b) #define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c) #define scl(a) scanf("%lld",&a) #define scll(a,b) scanf("%lld%lld",&a,&b) #define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c) #define prl(a) printf(

「Luogu P3332」K大数查询

不羁的心 提交于 2020-02-06 21:34:06
你需要维护 \(n\) 个可重整数集,集合的编号从 \(1\) 到 \(n\) 。 这些集合初始都是空集,有 \(m\) 个操作: 1 l r c :表示将 \(c\) 加入到编号 \([l, r]\) 内的集合中 2 l r c :表示查询编号在 \([l, r]\) 内的集合的并集中,第 \(c\) 大的数是多少。 Luogu 分析 经典的整体二分题,这里是区间修改,所以用到的的树状数组也要是支持区间修改的,可以参考 树状数组 代码 #include <bits/stdc++.h> #define N 50003 #define rg register #define lowbit(i) i&-i #define ll long long using namespace std; int gi() { int x = 0, f = 1; char c = getchar(); for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1; for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return x * f; } struct Opt { int type, x, y, id; ll c; } q[N], q1[N], q2[N]; int n, m,

JSOI2014

不羁的心 提交于 2020-02-05 11:46:13
B 宅男计划 题面: bzoj 题解:三分+贪心 可以发现一个 显然的 性质 就是你买外卖的次数和你能维持的天数大概是成一个单峰函数 证明不会 于是我们三分峰值 然后找到这个次数后再贪心 首先把那些又贵又放不久的扔掉,可以用单调栈 然后从最便宜的开始往上贪心 code C 骑士游戏 题面: bzoj 题解:最短路? 可以显然的写出一个dp方程,然而你会发现会有环 我们发现这个方程的形式和spfa的转移形式差不多 所以把所有点扔到队列里,初值设置魔法攻击的代价,跑最短路 如果这个点被更新了,则反图上与它相连的点都有可能更新,入队 codeC F 奇怪的计算器 题面: bzoj 题解:线段树 首先将这些值,因为不管怎么样都不会改变他们的大小关系 区间修改,如果最小的值小于下界就直接推平,上界同理 codeF G 支线剧情2 题面: bzoj 题解:树形dp 设 \(f[i]\) 表示这个点有存档,之后都不存档的最少代价 \[f[u]=\sum_{(u,v,w)\in E}{f[v]+siz[v]*w}\] 设 \(dp[u]\) 表示这个点子树内有存档的最小代价 如果当前点存档,儿子也有一个存档则 \(dp[u]+=dp[v]+deep[v]\) , \(deep\) 为从1到这个点的距离 否则直接转移(就是枚举一个最小值) codeG I 强连通图 题面: bzoj 题解:缩点