freopen

【统计难题】【HDU - 1251】【map打表或字典树】【字典树模板】

会有一股神秘感。 提交于 2019-11-27 16:55:38
思路 题意 : 题目 为中文题,这里不再过多阐述。 思路1 :可以在读入单词表的过程中将单词分解,用map将它一 一记录 思路2 :利用字典树,这个方法较快些,下面代码中会分别给出数组和结构体指针两种形式的字典树,指针形式的有时可能会因题目内存限制而导致Memory Limit Exceeded,这时就可选择数组形式的。不过对于本题来说不用担心。 AC代码 代码1:map打表 #include<bits/stdc++.h> using namespace std; typedef long long LL; map<string, int> table; int main() { std::ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); table.clear(); string s; while(getline(cin, s)) { if(s[0] == '\0') break; string ss = ""; for(int i = 0; i < s.size(); i++) { ss += s[i]; table[ss]++; } } while(cin >> s) { cout << table[s] <<

【noip2014】day1

百般思念 提交于 2019-11-27 15:11:22
T1 [模拟] 找循环节直接模拟即可。 【code】 #include<bits/stdc++.h> using namespace std; #define ll long long #define File "rps" inline void file(){ freopen(File".in","r",stdin); freopen(File".out","w",stdout); } inline int read(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0'; ch=getchar();} return x*f; } const int MAXN = 200 + 10; int n, na, nb, a[MAXN], b[MAXN], cnta, cntb; int vs[5][5] = {{0,0,1,1,0},{1,0,0,1,0},{0,1,0,0,1},{0,0,1,0,1},{1,1,0,0,0}}; //得分表的处理 int main(){ file(); n = read(),na = read(),nb = read(); for(int

2019 Multi-University Training Contest 4

怎甘沉沦 提交于 2019-11-27 13:43:25
2019 Multi-University Training Contest 4 A - AND Minimum Spanning Tree 题意:设 \(x\) 号结点与 \(y\) 号结点之间的边权为 \(x\ and\ y\) ,求 \(n\) 个点的图的最小生成树。如果有多种答案,输出从2号点开始连接的节点编号字典序最小的答案。 题解:对于每个数,按最低位 \(0\) 的位置取反得到一个与之相连的数。如果大于 \(n\) 就连 \(1\) 。 #include <bits/stdc++.h> #define fopi freopen("in.txt", "r", stdin) #define fopo freopen("out.txt", "w", stdout) using namespace std; typedef long long LL; const int maxn = 2e5 + 5; int T, n; int get(int x) { int res; for (int i = 0; i <= 20; i++) if (!((res = 1<<i) & x)) break; return res > n ? 1 : res; } int a[maxn]; int main() { scanf("%d", &T); for (int ca = 1; ca <

LOJ2984[WC2019]远古计算机(构造)

自闭症网瘾萝莉.ら 提交于 2019-11-27 13:12:31
神仙造计算机题。。。 计算机造计算机 subtask 1: 理解了这个题的应该都能写出来。 node 1 read 0 a write a 0 subtask 2: 看到只有一个计算机,内存还只有两个数就明显不能真算了,打表出斐波那契数列,注意要求周期尽量少,所以应该用jmp语句来打表。 1 node 1 2 read 0 a 3 add a 4 4 jmp a//可以对照行号看一下,a+4行对应的就是相应的第a项 5 write 0 0 6 write 1 0 7 write 1 0 8 write 2 0 9 write 3 0 10 write 5 0 //自己动手丰衣足食 49 write 701408733 0 subtask 3: 在图上bfs,找出1到n的路径,构造即可。 bfs: #include<cstdio> #include<queue> using namespace std; int G[105],to[250],nxt[250],sz=0,pre[105],st[105],sl=-1; bool vis[205]; queue<int> Q; inline void add(int u,int v){ to[++sz]=v;nxt[sz]=G[u];G[u]=sz; to[++sz]=u;nxt[sz]=G[v];G[v]=sz; } int main(

【noip2014】day2

回眸只為那壹抹淺笑 提交于 2019-11-27 13:03:39
T1 [前缀和,差分] 求二维前缀和然后大概差分一下就好了? 【code】 #include<bits/stdc++.h> using namespace std; #define ll long long #define File "wireless" inline void file(){ freopen(File".in","r",stdin); freopen(File".out","w",stdout); } inline int read(){ int x = 0,f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){if(ch=='-')f = -1; ch = getchar();} while(ch >= '0' && ch <= '9'){x = (x<<1) + (x<<3) + ch-'0'; ch = getchar();} return x*f; } const int mxn = 130; int d,n; int s[mxn][mxn]; int a[mxn][mxn]; inline int Q(int x_1,int y_1,int x_2,int y_2){ return s[x_2][y_2] - s[x_1-1][y_2] - s[x_2][y_1-1] + s[x_1-1][y_1

Luogu-P2627 修剪草坪

£可爱£侵袭症+ 提交于 2019-11-27 12:59:05
题目 题目链接 测试得分:   100 主要算法 :  单调队列优化DP 题干:   单调队列优化DP板子 分析   单调队列优化DP定长连续区间最值问题模型   代码   70分朴素DP #include<stdio.h> #include<stdlib.h> #define FORa(i,s,e) for(int i=s;i<=e;i++) #define FORs(i,s,e) for(int i=s;i>=e;i--) #define LL long long #define gc getchar()//pa==pb&&(pb=(pa=buf)+fread(buf,1,100000,stdin),stdin)?EOF:*pa++ #define File(name) freopen(name".in","r",stdin);freopen(name".out","w",stdout); using namespace std; char buf[100000],*pa,*pb; inline int read(); const int N=1e6; int n,k; LL sum[N+1],f[N+1][2]; f[i][1]代表从1-i这段区间,i这个位置的奶牛选取的效率最大值 f[i][0]代表从1-i这段区间,i这个位置的奶牛不选取的效率最大值 inline LL

【模拟赛】纪中提高A组 19.8.9 测试

别来无恙 提交于 2019-11-27 10:49:23
Task.1 走格子 题目大意:C和F在一个可以看作 \(N\times M\) 的矩阵的房间中,矩阵中的每一个元素可以是: 障碍:"#" C或者F的起点:"C"或"F" 空区域:"." C携带了一把传送枪,每次C都可以: 花费一个单位时间移动到相邻的空区域 不花费时间向上下左右之一的方向的墙壁上发射传送门 (传送门最多只能同时存在两扇,如果已经存在两扇再发射一扇那最早出现的那扇会消失,一个位置不能存在两扇传送门) 花费一个单位时间进入相邻墙壁上的传送门中移动到另一个传送门前方的格子中。 求C到F的最短时间。 数据范围: \(1\leq N,M\leq 500\) ,保证地图最外围是障碍。 https://store.steampowered.com/app/400/Portal/ 上来我们就想想爆搜?能过吗? 可以拿到85pts的好成绩??? 正确的操作是这样的:当你在某个位置时,你可以向四个方向上发射两个传送门,一定可以走到那个最近的墙边进传送门到另外一面墙前面。 做法就很简单了:bfs或最短路算法,考虑一下上述情况就可以了。 代码: #include<stdio.h> #include<string.h> #include<algorithm> #include<vector> #include<queue> #include<utility> using namespace

20190814校内模拟赛

妖精的绣舞 提交于 2019-11-27 08:31:09
T1.坏掉的键盘 (keyboard) 传送门 Description \(n\times m\) 网格,从左上走到右下,只能往下或往右 有一些障碍物,数量 \(\leq 10^5\) 询问能否到达, \(n,m\leq 10^9\) Solution 直接暴力维护每行可以到达的区间即可 Code //70pts 离散后暴力算方案数 #include<bits/stdc++.h> #define ll long long #define db double #define reg register #define dbg1(x) cerr<<#x<<"="<<(x)<<" " #define dbg2(x) cerr<<#x<<"="<<(x)<<"\n" #define dbg3(x) cerr<<#x<<"\n" #define int ll using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();} return x*f; } const int MN=4e5+5,P

挖宝藏

放肆的年华 提交于 2019-11-27 07:03:35
Solution 这是一个较经典的斯坦纳树模型 就是把一堆点串起来的最小代价。 所以说最小生成树只是斯坦纳树的一个特殊情况. 所以我们可以设f[i][j][k][S]表示在当前(i,j,k)这个位置上,我们在同层已经选了集合为S的点的最小代价 方程可以写成 \[f[i][j][k][S]=f[i][j][k][s]+f[i][j][k][S-s]-a[i][j][k];\] 这里要记录一下这个特殊的枚举子集的方法。 普通我们枚举子集都是直接先 \(2^n\) 再加上 \(2^n\) 的枚举就是 \(4^n\) 但是斯坦纳树的枚举方法是每次把最后面的一个一去掉,然后再&一下原数,补回前面的1 具体代码是这样的 for (s=S&(S-1);s;s=S&(s-1)) Code #include<cstdio> #include<iostream> #include<cstring> using namespace std; const long long maxn=10+1; const long long maxs=1<<10; const long long fx[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; long long h,n,m,tot; long long f[maxn][maxn][maxn][maxs]; long long a[maxn]

8.9 Round 1

拈花ヽ惹草 提交于 2019-11-26 17:42:48
今天是这几天考试中唯一一次发挥正常一点儿的... T1:https://www.luogu.org/problem/T93119 这么小的数据,O(n^3)暴力就行 而我非常愚蠢加个二分,一样可以过 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<climits> #include<map> #include<queue> #include<cmath> using namespace std; #define O(x) cout << #x << " " << x << endl; #define B cout << "breakpoint" << endl; #define clr(a) memset(a,0,sizeof(a)); inline int read() { int ans = 0,op = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') op = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { (ans *= 10) += ch - '0'; ch = getchar(); } return ans