2018/02/26 模拟赛

第一题排序暴力

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<string>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<utility>
 8 #include<stdio.h>
 9 #include<cstdlib>
10 #include<iomanip>    //cout<<setiosflags(ios::fixed)<<setprecision(2);
11 #include<ctime> //double a=(double)clock();    cout<<a<<endl;
12 #include<vector>
13 #include<queue>
14 #include<set>
15 #include<map>
16 using namespace std;
17 int read(){
18     int x=0,ff=1;char ch=getchar();
19     while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘)ff=-1; ch=getchar();}
20     while(ch<=‘9‘&&ch>=‘0‘){x=x*10+ch-‘0‘;ch=getchar();}
21     return ff*x;
22 }
23 map<int,int>mp;
24 int N,a,b[100010];
25 long long ans;
26 int main(){
27     freopen("expedition.in","r",stdin);
28     freopen("expedition.out","w",stdout);
29     N=read();
30     for(int i=1;i<=N;i++){
31         a=read(),b[i]=read();
32         mp[b[i]]+=a;
33     }
34     sort(b+1,b+1+N);
35     for(int i=1;i<=N;i++)
36         if(b[i]!=b[i-1])
37             ans+=1LL*mp[b[i]]*mp[b[i]];
38     printf("%I64d\n",ans);
39     return 0;
40 }

第二题计算表达式,对于多项式用类似高精度的方法计算

  1 #include<iostream>
  2 #include<cstring>
  3 #include<cstdio>
  4 #include<string>
  5 #include<algorithm>
  6 #include<cmath>
  7 #include<utility>
  8 #include<stdio.h>
  9 #include<cstdlib>
 10 #include<iomanip>    //cout<<setiosflags(ios::fixed)<<setprecision(2);
 11 #include<ctime> //double a=(double)clock();    cout<<a<<endl;
 12 #include<vector>
 13 #include<queue>
 14 using namespace std;
 15 int read(){
 16     int x=0,ff=1;char ch=getchar();
 17     while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘)ff=-1; ch=getchar();}
 18     while(ch<=‘9‘&&ch>=‘0‘){x=x*10+ch-‘0‘;ch=getchar();}
 19     return ff*x;
 20 }
 21 const int MOD=10007;
 22 struct bignum{
 23     int num[510];
 24     int len;
 25     void clear()
 26     {len=0,memset(num,0,sizeof(num));}
 27     void print(){
 28         printf("%d\n",len);
 29         for(int i=0;i<=len;i++){
 30             if(num[i]<0)
 31                 num[i]+=MOD;
 32             printf("%d\n",num[i]);
 33         }
 34     }
 35     bignum friend operator+(const bignum&A,const bignum&B){
 36         bignum C;
 37         C.len=max(A.len,B.len);
 38         for(int i=0;i<=C.len;i++){
 39             if(i>A.len)
 40                 C.num[i]=B.num[i];
 41             else if(i>B.len)
 42                 C.num[i]=A.num[i];
 43             else
 44                 C.num[i]=(A.num[i]+B.num[i])%MOD;
 45         }
 46         while(C.num[C.len]==0&&C.len)
 47             C.len--;
 48         return C;
 49     }
 50     bignum friend operator-(const bignum&A,const bignum&B){
 51         bignum C;
 52         C.len=max(A.len,B.len);
 53         for(int i=0;i<=C.len;i++){
 54             if(i>A.len)
 55                 C.num[i]=-B.num[i];
 56             else if(i>B.len)
 57                 C.num[i]=A.num[i];
 58             else
 59                 C.num[i]=(A.num[i]-B.num[i])%MOD;
 60         }
 61         while(C.num[C.len]==0&&C.len)
 62             C.len--;
 63         return C;
 64     }
 65     bignum friend operator*(const bignum&A,const bignum&B){
 66         bignum C;
 67         C.clear();
 68         for(int i=0;i<=A.len;i++)
 69             for(int j=0;j<=B.len;j++){
 70                 int k=i+j;
 71                 C.num[k]+=A.num[i]*B.num[j];
 72                 C.num[k]%=MOD;
 73                 if(k>C.len&&C.num[k]!=0)
 74                     C.len=k;
 75             }
 76         return C;
 77     }
 78 }p[1010],t;//多项式栈
 79 char s[1010];
 80 int N;
 81 char op[1010];//operator 运算符栈
 82 int to,tp;
 83 inline int grade(char c){
 84     if(c==‘+‘||c==‘-‘)
 85         return 1;
 86     else if(c==‘*‘)
 87         return 2;
 88     else
 89         return 0;
 90 }
 91 int main(){
 92     freopen("simplify.in","r",stdin);
 93     freopen("simplify.out","w",stdout);
 94     gets(s+1);
 95     N=strlen(s+1);
 96     for(int i=1;i<=N;i++){
 97         if(s[i]==‘x‘){
 98             tp++;
 99             p[tp].len=1;
100             p[tp].num[0]=0;
101             p[tp].num[1]=1;
102         }
103         else if(s[i]>=‘0‘&&s[i]<=‘9‘){
104             int j=i,temp=0;
105             while(s[j]>=‘0‘&&s[j]<=‘9‘){
106                 temp=temp*10+s[j]-‘0‘;
107                 j++;
108             }
109             tp++;
110             p[tp].len=0;
111             p[tp].num[0]=temp;
112             i=j-1;
113         }
114         else{
115             if(s[i]==‘(‘)
116                 op[++to]=s[i];
117             else if(s[i]==‘)‘){
118                 while(to&&op[to]!=‘(‘){
119                     tp--;
120                     if(op[to]==‘+‘)
121                         p[tp]=p[tp]+p[tp+1];
122                     else if(op[to]==‘-‘)
123                         p[tp]=p[tp]-p[tp+1];
124                     else
125                         p[tp]=p[tp]*p[tp+1];
126                     to--;
127                 }
128                 to--;
129             }
130             else{
131                 while(to&&grade(op[to])>=grade(s[i])){
132                     tp--;
133                     if(op[to]==‘+‘)
134                         p[tp]=p[tp]+p[tp+1];
135                     else if(op[to]==‘-‘)
136                         p[tp]=p[tp]-p[tp+1];
137                     else
138                         p[tp]=p[tp]*p[tp+1];
139                     to--;
140                 }
141                 op[++to]=s[i];
142             }
143         }
144     }
145     while(to){
146         tp--;
147         if(op[to]==‘+‘)
148             p[tp]=p[tp]+p[tp+1];
149         else if(op[to]==‘-‘)
150             p[tp]=p[tp]-p[tp+1];
151         else
152             p[tp]=p[tp]*p[tp+1];
153         to--;
154     }
155     p[tp].print();
156     return 0;
157 }

第三题最短路,“一到多”的最短路可以直接求,“多到一“的最短路可以将所有边反向后做最短路来求

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<string>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<utility>
 8 #include<stdio.h>
 9 #include<cstdlib>
10 #include<iomanip>    //cout<<setiosflags(ios::fixed)<<setprecision(2);
11 #include<ctime> //double a=(double)clock();    cout<<a<<endl;
12 #include<vector>
13 #include<queue>
14 using namespace std;
15 int read(){
16     int x=0,ff=1;char ch=getchar();
17     while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘)ff=-1; ch=getchar();}
18     while(ch<=‘9‘&&ch>=‘0‘){x=x*10+ch-‘0‘;ch=getchar();}
19     return ff*x;
20 }
21 const int maxn=3010,maxm=100010;
22 int N,M,Q;
23 struct Edge{
24     int x,y,v;
25 }E[maxm];
26 struct edge{
27     int y,next,v;
28 }e[maxm*2];
29 int lin[maxn],len;
30 inline void insert(int xx,int yy,int vv){
31     e[++len].next=lin[xx];
32     lin[xx]=len;
33     e[len].y=yy;
34     e[len].v=vv;
35 }
36 void build(bool sgn){
37     memset(lin,0,sizeof(lin));len=0;
38     if(!sgn)
39         for(int i=1;i<=M;i++)
40             insert(E[i].x,E[i].y,E[i].v);
41     else
42         for(int i=1;i<=M;i++)
43             insert(E[i].y,E[i].x,E[i].v);
44 }
45 int dis[2][maxn],q[2000010],head,tail;
46 bool vis[maxn];
47 void SPFA(int sgn){
48     head=0,tail=0;
49     q[head]=1;
50     vis[1]=1;
51     dis[sgn][1]=0;
52     for(;head<=tail;head++){
53         for(int i=lin[q[head]];i;i=e[i].next)
54             if(dis[sgn][q[head]]+e[i].v<dis[sgn][e[i].y]){
55                 dis[sgn][e[i].y]=dis[sgn][q[head]]+e[i].v;
56                 if(!vis[e[i].y]){
57                     vis[e[i].y]=1;
58                     q[++tail]=e[i].y;
59                 }
60             }
61         vis[q[head]]=0;
62     }
63 }
64 int main(){
65     freopen("production.in","r",stdin);
66     freopen("production.out","w",stdout);
67     N=read(),M=read();
68     for(int i=1;i<=M;i++)
69         E[i].x=read(),E[i].y=read(),E[i].v=read();
70     memset(dis,10,sizeof(dis));
71     build(0);
72     SPFA(0);
73     build(1);
74     SPFA(1);
75     Q=read();
76     for(int i=1;i<=Q;i++){
77         int tx=read(),ty=read();
78         if(dis[1][tx]+dis[0][ty]>=dis[0][0])//dis[0][0]==INF
79             printf("-1\n");
80         else
81             printf("%d\n",dis[1][tx]+dis[0][ty]);
82     }
83     return 0;
84 }

原文地址:https://www.cnblogs.com/lzhAFO/p/8472604.html

时间: 2024-08-30 05:26:47

2018/02/26 模拟赛的相关文章

2018/5/24模拟赛总结

shzr带病AK虐爆全场... T1n皇后: 这题没啥好说的... T2有重复元素的排列问题: [问题描述] 设R={ r1, r2 , -, rn}是要进行排列的n个元素.其中元素r1, r2 , -, rn可能相同.试设计一个算法,列出R的所有不同排列. [编程任务] 给定n 以及待排列的n 个元素.计算出这n 个元素的所有不同排列. [输入格式] 由perm.in输入数据.文件的第1 行是元素个数n,1≤n≤500.接下来的1 行是待排列的n个元素. [输出格式] 计算出的n个元素的所有不

9.26模拟赛

NOIP 2017 全真模拟冲刺 ---LRH&&XXY 题目名称 那些年 铁路计划 毁灭 题目类型 传统 传统 传统 可执行文件名 years trainfare destroy 输入文件名 years.in trainfare.in destroy.in 输出文件名 years.out trainfare.out destroy.out 每个测试点时限 1.5s 1.0s 1.0s 内存限制 256 MB 256 MB 256 MB 测试点数目 20 20 20 每个测试点分值 5 5

2018.02.26 9周4次课

九周第四次课(2月26日) 11.1 LAMP架构介绍 11.2 MySQL.MariaDB介绍 11.3/11.4/11.5 MySQL安装 11.1 LAMP架构介绍 MySQL.MariaDB介绍 MySQL是一个关系型数据库,由mysql ab公司开发,mysql在2008年被sun公司收购(10亿刀),2009年sun公司被oracle公司收购(74亿刀) MySQL官网https://www.mysql.com  最新版本5.7GA/8.0DMR MySQL5.6变化比较大,5.7性

2018/3/19 模拟赛 35分

T1 不会计算几何弃疗了. T2 写了个bitset结果还不如不优化(手动滑稽),因为测样例开小了空间忘了开回去所以0分. 正解是FFT,不会FFT.. T3 暴力35分,正解倍增floyd,学长还讲过但是还是错了,又多了一个要学的知识点. 原文地址:https://www.cnblogs.com/137shoebills/p/8602386.html

2018.7.3模拟赛

我真的是菜的一笔 T1: 一道贪心大水题,然后我wa了... 就是把它按照结束时间排个序,然后乱搞一下就行了 #include <cstdio> #include <cstdlib> #include <algorithm> int n,ans; struct Node{int t,s,k;} r[100005]; bool cmp(Node x,Node y){if(x.s!=y.s) return x.s<y.s;return x.k<y.k;} int

2018.11.1模拟赛总结

贪心 + 堆 因为可以不选满,所以可以把小于 \(0\) 的值赋值为 \(0\), 先考虑按 \(a_i\) 从大到小排序, 然后考虑选择 \([A + 1 \dots n]\) 中最大的 \(b_i\).但是这样不一定会成为最优解,我们从 \(A + 1\) 开始向 \(A + B\) 扫描,每一次尝试放弃前面的一个 \(a_i\) , 然后用当前的物品更新 \(a_i\) 的答案.前者可以通过用一个包含了第 \(A\) 个物品的 \(b_i - a_i\) 的 \(set\) 维护,后者可以

树的dfs序,p1539,其他经典问题,2018/11/08模拟赛T3

树的dfs序指从根节点进行dfs(先序遍历),每次到达某个点的时间和离开这个点的时间.它可以将树上的问题转换成序列问题进行处理. 比如对于p1539的样例可以这样解释. 每个点的左边数字表示进入该点的"时间",右边的数字表示离开该点的"时间".对dfs序的介绍就到这里. 然后来看一个例题: 先读入边,跑一遍dfs确定dfs序. 对于操作1,把点x的进入的"时间"+=a,把x出去的"时间"-=a 这样操作3询问根节点到y的路径点

2019.9.26模拟赛

T1序列 这个题大佬们爆踩std了 给一个序列,其中一段排序后是某一等比数列子序列,求最长长度. 怎么做 数据太水导致枚举公比的过了 序列中每两个数做商,如果整除了的话,这个商一定是公比的次幂.我们从大到小枚举它是公比的几次幂,从而求到最小的公比.由于\(2^{60} > 1^{18}\),这个枚举只需要从59开始即可.时间复杂度\(O(64n)\) Code pow有精损注意判一下.(不要瞎搞手写分数次幂) #include <bits/stdc++.h> namespace fdat

2019.10.26模拟赛

T1 序列 给定一长度为\(n\)的序列\(s\),定义其健美值为:\[\sum\limits_{i=1}^{n}|s_i - i|\]因为 zzq 喜欢健美,所以 zzq 希望减小\(s\)的健美值,以衬托 zzq 的健美.为了达到 zzq 的目的,zzq 希望你对序列进行旋转操作,一次旋转操作可以使序列中的所有元素前移一位,并使\(s_1\)移动到\(s_n\). 可以进行任意次旋转操作,zzq 希望旋转后的健美值最小,请找出这个最小值. SOV 智商检测题 我们发现对于每个数,移动每一次会