10.16NOIP模拟赛
- /*
- 我是一个大sb
- */
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<queue>
- #include<algorithm>
- #define ll long long
- #define N 10000007
- #define mod 1000000000
- using namespace std;
- ll n,m,k,x,y,flag,ans,cnt;
- ll a[N],cur[N];
- priority_queue<ll>q;
- inline ll read()
- {
- ll x=,f=;char c=getchar();
- while(c>''||c<''){if(c=='-')f=-;c=getchar();}
- while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
- return x*f;
- }
- int main()
- {
- freopen("shop.in","r",stdin);
- freopen("shop.out","w",stdout);
- n=read();m=read();
- x=read();y=read();
- a[]=x;q.push(-a[]);
- for(int i=;i<=n;i++)
- {
- a[i]=(y*a[i-]+x)%mod;
- q.push(-a[i]);
- if(a[i]==){k=i;break;}
- }
- if(!k)
- {
- for(int i=;i<=m;i++)
- {
- ll res=q.top();q.pop();
- ans-=res;
- }
- cout<<ans<<endl;
- return ;
- }
- int t=n/k,tt=n-t*k;a[t*k+]=x;cur[++cnt]=x;
- for(int i=;i<=tt;i++)
- {
- a[i+t*k]=(y*a[i+t*k-]+x)%mod;
- cur[++cnt]=a[i];
- }
- sort(cur+,cur+tt+);
- if(m<=t) ans=;
- else
- {
- while(!q.empty() && m)
- {
- int x=q.top();q.pop();x=-x;
- if(x<cur[] || x>cur[tt])
- {
- m-=t;ans+=x*t;
- }
- if(x>=cur[] && x<=cur[tt])
- {
- m-=(t+);ans+=x*(t+);
- }
- }
- }
- cout<<ans<<endl;
- fclose(stdin);fclose(stdout);
- return ;
- }
50找循环节。。。
- /*
- 优先队列
- */
- #include<complex>
- #include<cstdio>
- #include<queue>
- using namespace std;
- const int mod=1e9;
- long long n,m,x,y,ans;
- priority_queue<int>q;
- int main()
- {
- freopen("shop.in","r",stdin);
- freopen("shop.out","w",stdout);
- scanf("%d%d%d%d",&n,&m,&x,&y);
- long long now=x;
- q.push(now);
- for(int i=;i<=n;i++)
- {
- now=(now*y+x)%mod;
- if(i<=m)q.push(now);
- else if(now<q.top())
- {
- q.pop();
- q.push(now);
- }
- }
- while(!q.empty())
- {
- ans+=q.top();
- q.pop();
- }
- printf("%I64d\n",ans);
- fclose(stdin);fclose(stdout);
- return ;
- }
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #define N 100007
- using namespace std;
- int n,m,k,cnt;
- int a[N],b[N];
- double c[N],ans;
- inline int read()
- {
- int x=,f=;char c=getchar();
- while(c>''||c<''){if(c=='-')f=-;c=getchar();}
- while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
- return x*f;
- }
- void dfs(int now,int sum,double p)
- {
- if(now==n+)
- {
- ans+=double(sum)*p;
- return;
- }
- if(a[now]==)
- {
- dfs(now+,sum & b[now],p*(1.000-c[now]));
- dfs(now+,sum,p*c[now]);
- }
- if(a[now]==)
- {
- dfs(now+,sum | b[now],p*(1.000-c[now]));
- dfs(now+,sum,p*c[now]);
- }
- if(a[now]==)
- {
- dfs(now+,sum ^ b[now],p*(1.000-c[now]));
- dfs(now+,sum,p*c[now]);
- }
- }
- int main()
- {
- // freopen("exp.in","r",stdin);
- // freopen("exp.out","w",stdout);
- n=read();
- for(int i=;i<=n;i++) a[i]=read();
- for(int i=;i<=n;i++) b[i]=read();
- for(int i=;i<=n;i++) scanf("%lf",&c[i]);
- ans=;dfs(,,);
- printf("%.1lf\n",ans);
- fclose(stdin);fclose(stdout);
- return ;
- }
40暴力
- /*
- 把每一位拆开单独考虑
- f[i][0/1]表示到第i个运算,该位为0/1的概率
- 对于每一个运算符分情况讨论
- ans = sum[ f[n][1] * (1 << k) ]
- */
- #include<bits/stdc++.h>
- #define N 100007
- using namespace std;
- int n,a[N],b[N];
- double c[N], f[N][];
- inline int read()
- {
- int x=,f=;char c=getchar();
- while(c>''||c<''){if(c=='-')f=-;c=getchar();}
- while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
- return x*f;
- }
- double solve(int bit)
- {
- f[][]=1.00;
- for(int i=;i<=n;i++)
- {
- int x = b[i] >> bit & ;
- if(a[i]==)
- {
- if(x==) f[i][]=(f[i-][] + f[i-][]) * ( - c[i]) + f[i-][] * c[i],
- f[i][]=f[i-][] * c[i];
- else f[i][]=f[i-][],
- f[i][]=f[i-][];
- }
- if(a[i]==)
- {
- if(x==) f[i][]=f[i-][],
- f[i][]=f[i-][];
- else f[i][]=f[i-][] * c[i],
- f[i][]=(f[i-][] + f[i-][]) * ( - c[i]) + f[i-][] * c[i];
- }
- if(a[i] == )
- {
- if(x==) f[i][]=f[i-][],
- f[i][]=f[i-][];
- else f[i][]=f[i-][] * ( - c[i]) + f[i-][] * c[i],
- f[i][]=f[i-][] * ( - c[i]) + f[i-][] * c[i];
- }
- }
- return f[n][];
- }
- int main()
- {
- freopen("exp.in", "r", stdin);
- freopen("exp.out", "w", stdout);
- cin>>n;
- for(int i = ;i<=n;i++) cin>>a[i];
- for(int i = ;i<=n;i++) cin>>b[i];
- for(int i = ;i<=n;i++) scanf("%lf",&c[i]);
- double ans = ;
- for(int i = ;i>=;i--) ans+=(double)(1ll << i) * solve(i);
- printf("%.1lf",ans);
- return ;
- }
、、
- #include<bits/stdc++.h>
- #define N 50001
- using namespace std;
- int n,m,T,ans,cnt,res,num;
- int head[N],deep[N],sum[N];
- int f[N][],tmp1[N],tmp2[N];
- struct edge{
- int u,v,w,net;
- }e[N<<];
- inline int read()
- {
- int x=,f=;char c=getchar();
- while(c>''||c<''){if(c=='-')f=-;c=getchar();}
- while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
- return x*f;
- }
- inline void add(int u,int v,int w)
- {
- e[++cnt].v=v;e[cnt].w=w;e[cnt].net=head[u];head[u]=cnt;
- }
- void dfs(int u,int fa,int c)
- {
- f[u][]=fa;deep[u]=c;
- for(int i=head[u];i;i=e[i].net)
- {
- int v=e[i].v;
- if(v==fa) continue;
- sum[v]+=e[i].w+sum[u];
- dfs(v,u,c+);
- }
- }
- void get()
- {
- for(int j=;j<=;j++) for(int i=;i<=n;i++)
- f[i][j]=f[f[i][j-]][j-];
- }
- int lca(int a,int b)
- {
- if(deep[a]<deep[b]) swap(a,b);
- int t=deep[a]-deep[b];
- for(int i=;i<=;i++)
- if(t&(<<i)) a=f[a][i];
- if(a==b) return a;
- for(int i=;i>=;i--)
- {
- if(f[a][i]!=f[b][i])
- a=f[a][i],b=f[b][i];
- }return f[a][];
- }
- void solve1(int x,int L,int k)
- {
- cnt=;
- while(x!=L)
- {
- tmp1[++cnt]=sum[x]-sum[f[x][]];
- x=f[x][];
- }
- }
- void solve2(int y,int L,int k)
- {
- num=;
- while(y!=L)
- {
- tmp2[++num]=sum[y]-sum[f[y][]];
- y=f[y][];
- }
- }
- int main()
- {
- //freopen("data.txt", "r", stdin);
- //freopen("2.out", "w", stdout);
- freopen("maze.in","r",stdin);
- freopen("maze.out","w",stdout);
- //freopen("ly.in","r",stdin);
- //freopen("ly.out","w",stdout);
- int x,y,z;
- n=read();
- for(int i=;i<n;i++)
- {
- x=read();y=read();z=read();
- add(x,y,z);add(y,x,z);
- }
- dfs(,,);get();
- m=read();
- for(int i=;i<=m;i++)
- {
- x=read();y=read();z=read();
- int L=lca(x,y);
- memset(tmp1,,sizeof tmp1);
- memset(tmp2,,sizeof tmp2);
- solve1(x,L,z);
- solve2(y,L,z);reverse(tmp2+,tmp2+num+);
- ans=;res=;
- if(cnt)
- for(int i=;i<=cnt;i++)
- {
- if(tmp1[i]<=res) res-=tmp1[i];
- else res=z,res-=tmp1[i],ans++;
- }
- if(num)
- for(int i=;i<=num;i++)
- {
- if(tmp2[i]<=res) res-=tmp2[i];
- else res=z,res-=tmp2[i],ans++;
- }
- printf("%d\n",ans);
- }
- fclose(stdin);fclose(stdout);
- return ;
- }
35暴力
- /*
- LCA,压位
- 算 LCA 是显然的, 由于两个点之间可能要走很多步, 所以我们预处理每一个点往上连续
- 走六步会出现的各种情况,便能控制常数,从而在 8 秒内出解。由于边权只有两种,所以一
- 个点往上走六步遇到的边权只有 2^6 = 64 种情况
- */
- #include <cstdio>
- #include <cstring>
- #define E 50010
- #define F 100010
- using namespace std;
- int n, m, head[E], to[F], next[F], value[F], cnt = , cost = , costa = ;
- void Read(int &x)
- {
- char ch = getchar();
- x = ;
- while (ch < '' || ch > '') ch = getchar();
- while (ch >= '' && ch <= '')
- {
- x = x * + ch - '';
- ch = getchar();
- }
- }
- void add(int x, int y, int z)
- {
- to[++cnt] = y; value[cnt] = z; next[cnt] = head[x]; head[x] = cnt;
- }
- int fa[E][], dep[E], dist[E][], type[E], jky[E][], dd[E], jump[E];
- short czy[<<][][][];
- void dfs(int u, int f, int d)
- {
- fa[u][] = f;
- dep[u] = d;
- for (int j = head[u]; j; j = next[j])
- {
- int v = to[j];
- if (v == f) continue;
- dist[v][] = value[j];
- dfs(v, u, d+);
- }
- }
- void build()
- {
- for (int k = ; k < ; k++)
- for (int u = ; u <= n; u++)
- {
- fa[u][k] = fa[fa[u][k-]][k-];
- if (k <= ) dist[u][k] = dist[u][k-] + dist[fa[u][k-]][k-];
- }
- for (int i = ; i <= n; i++)
- if (dep[i] >= ) dd[i] = dist[i][] + dist[fa[i][]][];
- for (int i = ; i <= n; i++)
- {
- if (dep[i] < ) continue;
- int t = , u = i;
- for (int j = ; j < ; j++)
- {
- if (dist[u][] == cost) t += << j;
- u = fa[u][];
- }
- jump[i] = u;
- type[i] = t;
- }
- for (int j = ; j < (<<); j++)
- for (int k = cost; k <= cost * ; k++)
- for (int rest = ; rest <= k; rest++)
- {
- int path = j, step = , re = rest;
- for (int t = ; t <= ; t++)
- {
- int co;
- if (path & ) co = cost; else co = costa;
- if (re < co) re = k, step++;
- re -= co;
- path >>= ;
- }
- czy[j][k][rest][] = step;
- czy[j][k][rest][] = re;
- }
- for (int i = ; i <= n; i++)
- {
- int u = i, rest = ;
- for (int j = ; j < dd[i]; j++)
- {
- if (dep[u] > && rest >= dist[u][])
- {
- rest -= dist[u][];
- u = fa[u][];
- }
- jky[i][j] = u;
- rest++;
- }
- }
- }
- void swap(int& x, int& y)
- {
- int t = x; x = y; y = t;
- }
- int get(int x, int y)
- {
- if (dep[x] < dep[y]) swap(x, y);
- for (int k = ; k >= ; k--)
- if (dep[fa[x][k]] >= dep[y]) x = fa[x][k];
- if (x == y) return x;
- for (int k = ; k >= ; k--)
- if (fa[x][k] != fa[y][k]) x = fa[x][k], y = fa[y][k];
- if (x != y) x = fa[x][];
- return x;
- }
- struct hyd
- {
- int step, rest;
- };
- inline hyd work(int u, int f, int k)
- {
- int step = , rest = ;
- if (k <= cost * )
- while (dep[u] > dep[f])
- {
- if (dep[u] - dep[f] < )
- {
- if (rest >= dist[u][]) rest -= dist[u][];
- else step++, rest = k - dist[u][];
- u = fa[u][];
- continue;
- }
- step += czy[type[u]][k][rest][];
- rest = czy[type[u]][k][rest][];
- u = jump[u];
- }
- else
- while (dep[u] > dep[f])
- {
- if (rest == ) step++, rest = k;
- if (dep[u] - dep[f] < )
- {
- if (rest >= dist[u][]) rest -= dist[u][];
- else step++, rest = k - dist[u][];
- u = fa[u][];
- continue;
- }
- if (rest >= dd[u])
- {
- rest -= dd[u];
- u = jump[u];
- continue;
- }
- u = jky[u][rest], rest = ;
- }
- return (hyd) {step, rest};
- }
- int main()
- {
- freopen("data.txt", "r", stdin);
- freopen("1.out", "w", stdout);
- Read(n);
- memset(head, , sizeof(head));
- for (int i = ; i < n; i++)
- {
- int x, y, z;
- Read(x), Read(y), Read(z);
- add(x, y, z);
- add(y, x, z);
- if (cost < z) cost = z;
- if (i == ) costa = z; else if (costa > z) costa = z;
- }
- memset(fa, , sizeof(fa));
- memset(dep, , sizeof(dep));
- memset(dist, , sizeof(dist));
- dfs(, , );
- build();
- Read(m);
- for (int i = ; i <= m; i++)
- {
- int x, y, k;
- Read(x), Read(y), Read(k);
- int f = get(x, y);
- hyd ans1 = work(x, f, k), ans2 = work(y, f, k);
- int ans = ans1.step + ans2.step;
- ans -= (ans1.rest + ans2.rest) / k;
- printf("%d\n", ans);
- }
- fclose(stdin); fclose(stdout);
- return ;
- }
10.16NOIP模拟赛的更多相关文章
- [10.18模拟赛] 序列 (DP)
[10.18模拟赛] 序列 题目描述 山山有一个整数序列s1,s2,-,sn,其中1≤si≤k. 求出有多少个准确移除m个元素后不同的序列.答案模(1e9+7) 输入 输入包括几个测试用例,并且由文件 ...
- [10.12模拟赛] 老大 (二分/树的直径/树形dp)
[10.12模拟赛] 老大 题目描述 因为 OB 今年拿下 4 块金牌,学校赞助扩建劳模办公室为劳模办公室群,为了体现 OI 的特色,办公室群被设计成了树形(n 个点 n − 1 条边的无向连通图), ...
- EZ 2018 06 10 NOIP2018 模拟赛(十八)
好久没写blog&&比赛题解了,最近补一下 这次还是很狗的,T3想了很久最后竟然连并查集都忘写了,然后T2map莫名爆炸. Rating爆减......链接不解释 好了我们开始看题. ...
- 2018.10.17NOIP模拟赛解题报告
心路历程 预计得分:\(100 + 100 +100\) 实际得分:\(100 + 100 + 60\) 辣鸡模拟赛.. 5min切掉T1,看了一下T2 T3,感觉T3会被艹爆因为太原了.. 淦了20 ...
- 洛谷P1667/[10.22 模拟赛] 数列 (思维+模拟)
洛谷P1667 数列 题目描述 给定一个长度是n的数列A,我们称一个数列是完美的,当且仅当对于其任意连续子序列的和都是正的.现在你有一个操作可以改变数列,选择一个区间[X,Y]满足\(A_X +A_{ ...
- 2018.10.23NOIP模拟赛解题报告
心路历程 预计得分:\(100 + 50 + (10 \sim 50)\) 实际得分:\(100 + 10 + 50\) 这可能是我打的最懵逼的一场考试没有之一.. T1两个小时才做出来也是醉了. T ...
- 17.2.10 NOIP模拟赛 聪哥的工资
聪哥的工资 (money/money.in/money.out) 时限1000ms 内存256MB 题目描述 lwher: 了体验劳苦大众的生活,聪哥在暑假参加了打零工的活动,这个活动分为n个工作日, ...
- 10.17NOIP模拟赛
#include<iostream> #include<cstdio> #include<cstring> #define N 1001 using namespa ...
- 2019.10.18模拟赛T3
题目大意: 求$\sum\limits_{i=1}^n\sum\limits_{j=1}^n[lcm(i,j)>n](n\leq 10^{10})$的值. 题解: 这题貌似有n多种做法... 为 ...
随机推荐
- Webdriver测试脚本2(控制浏览器)
Webdriver提供了操作浏览器的一些方法,例如控制浏览器的大小.操作浏览器前进和后退等. 控制浏览器窗口大小 有时候我们希望能以某种浏览器尺寸打开,让访问的页面在这种尺寸下运行.例如可以将浏览器设 ...
- english & utils & tools
english & utils & tools https://openlanguage.com/ https://www.grammarly.com/blog/email-writi ...
- [BZOJ3196] [Tyvj1730] 二逼平衡树(线段树 套 Splay)
传送门 至少BZOJ过了,其他的直接弃. 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 1.查询k在区间内的排名 2.查询区间内排名为k的值 3.修改某一位值上的 ...
- stl lower_bound()返回值
http://blog.csdn.net/niushuai666/article/details/6734403 函数lower_bound()在first和last中的前闭后开区间进行二分查找,返回 ...
- ModelForm组件和forms组件补充
forms组件补充: forms组件的三个字段:ChoiceField, ModelChoiceField & ModelMultipleChoiceField # forms组件:Choic ...
- cogs——2084. Asm.Def的基本算法
2084. Asm.Def的基本算法 ★☆ 输入文件:asm_algo.in 输出文件:asm_algo.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] “有句 ...
- Eclipse完成Maven + Spring Boot + Mybatis + jsp
Spring Boot 完成WEB项目开发 开发工具:eclipse 框架:Maven:Spring Boot:Mybatis 界面:jsp:javascript:css 前言: 在SpringBoo ...
- Servlet中操作数据库
以下内容引用自http://wiki.jikexueyuan.com/project/servlet/database-access.html: 前提先新建数据库及插入模拟数据: create tab ...
- LINUX 内核结构
http://blog.csdn.net/hguisu/article/details/6122513 http://blog.csdn.net/hguisu/article/category/796 ...
- C#的SplitPanel如何设置上下和左右
定位到Orientation属性即可