题目链接

设的私密,可能进不去,每个题有给原题链接。算作是私人题解吧。

A - Play the Dice HDU - 4586 

There is a dice with n sides, which are numbered from 1,2,...,n and have the equal possibility to show up when one rolls a dice. Each side has an integer ai on it. Now here is a game that you can roll this dice once, if the i-th side is up, you will get ai yuan. What's more, some sids of this dice are colored with a special different color. If you turn this side up, you will get once more chance to roll the dice. When you roll the dice for the second time, you still have the opportunity to win money and rolling chance. Now you need to calculate the expectations of money that we get after playing the game once.

题意:n面的色子,m面特殊面,进行一次掷色子,概率期望为p  第二次 m/n*p  第三次 m/n*m/n*p 。。。。求和就是等比求和公式

无限循环了怎么办。取极限 等比求和公式 

a1=m/n

分三种情况讨论:

1、当a1为0时,输出0.00;

2、当a1等于1时,说明可以无限的投掷下去,输出inf;

3、当a1< 1时,N无穷大时,1-q^N  的q^N 无限接近于0,那么原式变为a1/(1-q)。

#include<bits/stdc++.h>
using namespace std;
const int N=2e2+10;
int n,m,vis[N],a[N];
int sum,cnt;
double p,q;
const double eps=1e-6;
int main()
{while(~scanf("%d",&n)){sum = 0,cnt = 0;memset(vis,0,sizeof(vis));for(int i = 1; i <= n; i++){scanf("%d",&a[i]);sum += a[i];}p = (sum*1.0)/n;scanf("%d",&m);int x;for(int i = 1; i <= m; i++){cin >> x;if(vis[x]) continue;vis[x] = 1;cnt++;}q = (1.0*cnt)/n;if(fabs(p) < eps) puts("0.00");else if(fabs(q-1) < eps) puts("inf");else printf("%.2lf\n",p/(1-q));}return 0;
}

B - TWO NODES HDU - 4587

Suppose that G is an undirected graph, and the value of stab is defined as follows:


Among the expression,G -i, -j is the remainder after removing node i, node j and all edges that are directly relevant to the previous two nodes. cntCompent is the number of connected components of X independently.
Thus, given a certain undirected graph G, you are supposed to calculating the value of stab.

题意:去除两个点 使得剩下的图 联通块的个数 最大,

做法:百度有个人的博客刷屏了  他写的题意是强联通块的个数,如果是强连通块的话 下面这个样例答案应该是4  而他的代码是3

因为两个点只有一条线相连,那么这两个点属于不同的强连通

如果只是去除一个点的话 好做,用tarjan 计算一下 去除这个点时附近产生的 连通块的个数 即可

如果是去除两个点,枚举去除的那个点,然后再套用tarjan。

代码就懒的打了,贴的别人的

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
const int N=5010;
struct data
{int to,next;
} tu[N*N];
int head[N],low[N],dfn[N];///dfn[]记录某个点被访问到的次数,low[]记录某个点或其子树回边的最小步数的点
int cut[N];///是否为割点且该点连接边的数量
int ip;
int step,rt_son,scc_cnt;
void init()
{ip=0;memset(head,-1,sizeof(head));
}
void add(int u,int v)
{tu[ip].to=v,tu[ip].next=head[u],head[u]=ip++;
}
void tarjan(int u,int del)
{//cout<<u<<' ';dfn[u] = low[u] = step++;for(int i = head[u]; i!=-1 ; i=tu[i].next){int to = tu[i].to;if(to==del)continue;if(!dfn[to])///表示未被访问的点{tarjan(to,del);low[u]=min(low[u],low[to]);if(low[to]>=dfn[u])cut[u]++;}elselow[u]=min(low[u],dfn[to]);}
}
void solve(int n)
{int ans=0;for(int j=1; j<=n; j++){memset(dfn, 0, sizeof(dfn));for(int i=1; i<=n; i++)cut[i]=1;step = 1;int sum=0;for (int i = 1; i <=n; i++)if (i!=j&&!dfn[i]){sum++;//联通块的个数 cut[i]=0;tarjan(i,j);}for(int i=1; i<=n; i++)if(i!=j){//if(sum+cut[i]-1)ans=max(ans,sum+cut[i]-1);}}printf("%d\n",ans);
}
int main()
{int m,n;while(~scanf("%d%d",&n,&m)){init();while(m--){int a,b;scanf("%d%d",&a,&b);a++,b++;add(a,b);add(b,a);}solve(n);}return 0;
}
/*10 12
0 1
1 2
2 3
3 1
0 4
4 5
5 6
6 4
0 7
7 8
8 9
9 7*/ 

F - Shortest Subchain  URAL - 1651 

题意:给你一条单链,求此单链上 从起点出发到达终点最短的一条子链,意思就是说可能会有环,那么这个环去掉即可。

做法:对于 这条链上 前后出现了相同的点时 连一条长度为0 的边,其余的按照链上的顺序连权值为1的边,跑一次最短路,接着输出最短路就好了。很坑的是,题意没告诉你是多组输入,结果我单组输入 wa到炸

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;inline ll read()
{ll x=0,w=1; char c=getchar();while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}return w==1?x:-x;
}
const int N=1e5+10;
vector<pair<int,int> >G[N];
int n,a[N],vis[10010];
int dis[N],fa[N],ans[N];
struct node
{int u,w;bool operator <(const node &o) const{return w>o.w;}
};
void bfs()
{priority_queue<node>que;rep(i,1,n) dis[i]=1e9;dis[1]=0;que.push({1,dis[1]});while(que.size()){node now=que.top();que.pop();for(auto it:G[now.u]){if(dis[it.first]>dis[now.u]+it.second){dis[it.first]=dis[now.u]+it.second;fa[it.first]=now.u;que.push({it.first,dis[it.first]});}}}
}int main()
{while(~scanf("%d",&n)){rep(i,1,n) G[i].clear(),fa[i]=0;memset(vis,0,sizeof(vis));rep(i,1,n) a[i]=read();vis[a[1]]=1;for(int i=2;i<=n;++i){if(vis[a[i]]!=0) G[vis[a[i]]].push_back({i,0});vis[a[i]]=i;G[i-1].push_back({i,1});}bfs();//rep(i,1,n) printf("i:%d dis:%d\n",i,dis[i]);//int len=0;int now=n;stack<int>sta;while(now!=1){sta.push(now);now=fa[now];}sta.push(1);int pre=0;while(sta.size()){if(a[sta.top()]!=pre) printf("%d ",a[sta.top()]);pre=a[sta.top()];sta.pop();}puts("");}
}
/*
9
1 2 7 3 2 8 4 8 510
1 2 3 4 5 2 4 6 7 5
1 2 3 4 5
7
1 2 3 1 4 2 51 2 5
*/

G - Sum of Digits URAL - 1658 

Petka thought of a positive integer n and reported to Chapaev the sum of its digits and the sum of its squared digits. Chapaev scratched his head and said: “Well, Petka, I won't find just your number, but I can find the smallest fitting number.” Can you do the same?

题意:构造n位   每位和为s1  每位的平方和为2的最小的数。

做法:简单dp:dp[i][s1][s2] 第i为为dp[i][s1][s2]  和为s1  平方和为s2   。内存爆炸,简化一下,发现每个状态的dp 是唯一的。

于是去掉一维 dp[s1][s2]  用ans[s1][s2]保存到达s1、s2 需要填的数(1~9)

t组,预处理一下,然后逆着输出路径即可。

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;inline ll read()
{ll x=0,w=1; char c=getchar();while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}return w==1?x:-x;
}
int dp[901][8101],ans[901][8101];
void init()
{for(int i=0;i<=900;++i){for(int j=0;j<=8100;++j) dp[i][j]=inf;}dp[0][0]=0;for(int i=1;i<=900;++i){for(int j=1;j<=8100&&j<=i*i;++j){for(int k=1;k<=9;++k){if(i-k<0||j-k*k<0) break;if(i-k>j-k*k) break;if(dp[i][j]>dp[i-k][j-k*k]+1){dp[i][j]=dp[i-k][j-k*k]+1;ans[i][j]=k;}}}}
}
int main()
{init();int _=read();while(_--){int n=read(),m=read();if(n>900||m>8100){puts("No solution");continue;}if(dp[n][m]>100){puts("No solution");continue;}vector<int>res;while(n&&m){int now=ans[n][m];//printf("n:%d m:%d now:%d\n",n,m,now);res.push_back(ans[n][m]);n-=now,m-=now*now;}for(int v:res) printf("%d",v);puts("");}
}
/*
4
9 81
12 9
6 10
7 9
*/

H - Billionaires  URAL - 1650

题意:给定n个富豪的身价,以及最初始 所在的城市,然后m个富豪外出旅游的计划表。问每个城市 富豪的身价之和严格大于其他城市 时的天数。

做法:怎么URAL的题都这样,上一个题没讲多组输入,这个题又搞隐性题意,两个城市的身价之和 相同时 不贡献答案。

被这个不贡献答案卡了一个 小时。

让我想起了高中英语题 

题面:His mother was a nurse

题目:Is his mother a nurse?

答案是错的,因为题面 用的是过去式,题面问的现在时。这题 我们班英语130分的学霸还做错了。。。真的就是英语不好很吃亏(母语为英语的国家真好)。

复杂模拟,几个map 保存 富豪对应的身价,城市对应身价和  保存最大身价和的个数。线段树搞搞就好了。

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;inline ll read()
{ll x=0,w=1; char c=getchar();while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}return w==1?x:-x;
}
const int N=1e5+10;
int n,m,cnt,q;
map<string,string>name_city;
string tid[N];
map<string,int>vis;
set<string>st;
map<string,ll>city_num,name_num,ans;
map<ll,ll>num;ll x;
struct node
{string s;ll num;
};int t[N];
string name[N],city[N];
struct tree
{string city;ll x;
}mx[4*N];
tree Max(tree a,tree b)
{if(a.x>b.x) return a;return b;
}
void build(int id,int l,int r)
{if(l==r){mx[id].city=tid[l];mx[id].x=city_num[tid[l]];num[mx[id].x]++;return ;}int mid=l+r>>1;build(id<<1,l,mid);build(id<<1|1,mid+1,r);mx[id]=Max(mx[id<<1],mx[id<<1|1]);
}void up(int id,int l,int r,int pos,ll val)
{if(l==r){num[mx[id].x]--;mx[id].x+=val;num[mx[id].x]++;return ;}int mid=l+r>>1;if(pos<=mid) up(id<<1,l,mid,pos,val);else up(id<<1|1,mid+1,r,pos,val);mx[id]=Max(mx[id<<1],mx[id<<1|1]);
}bool cmp(node a,node b)
{return a.s<b.s;
}int main()
{n=read();rep(i,1,n){string s1,s2;cin>>s1>>s2>>x;name_city[s1]=s2;name_num[s1]=x;st.insert(s2);city_num[s2]+=x;}m=read(),q=read();rep(i,1,q){t[i]=read();cin>>name[i]>>city[i];st.insert(city[i]);}cnt=st.size();for(int i=1;i<=cnt;++i) {tid[i]=*st.begin();vis[*st.begin()]=i;st.erase(st.begin());}build(1,1,cnt);tree tmp=mx[1];int pre=0;rep(i,1,q){tree tmp=mx[1];if(num[tmp.x]==1) ans[tmp.city]+=t[i]-pre;ll val=name_num[name[i]];up(1,1,cnt,vis[name_city[name[i]]],-val);name_city[name[i]]=city[i];up(1,1,cnt,vis[city[i]],val);pre=t[i];}if(m>=pre){tree tmp=mx[1];if(num[tmp.x]==1) ans[tmp.city]+=m-pre;}for(auto now:ans) if(now.second)cout<<now.first<<" "<<now.second<<endl;}
/*
5
Abramovich London 15000000000
Deripaska Moscow 10000000000
Potanin Moscow 5000000000
Berezovsky London 2500000000
Khodorkovsky Chita 1000000000
25 9
1 Abramovich Anadyr
5 Potanin Courchevel
10 Abramovich Moscow
11 Abramovich London
11 Deripaska StPetersburg
15 Potanin Norilsk
20 Berezovsky Tbilisi
21 Potanin StPetersburg
22 Berezovsky London
*/

CCSU团队训练赛 ( A 数学 B tarjan F dij G dp H 线段树 )相关推荐

  1. 石油大--2020年秋季组队训练赛第十二场----J、Greedy Termite(线段树)

    题面: 题意: 给定正整数 nnn 和起始位置 sss. nnn 表示有 nnn 个杆子,每个杆子由属性 (xi,hi)(x_i,h_i)(xi​,hi​) 构成,表示在 xix_ixi​ 处有一根高 ...

  2. 石油大 2019年第二阶段我要变强个人训练赛第十八场 Problem N 扶桑号战列舰(线段树+区间更新+区间查询)

    链接:http://icpc.upc.edu.cn/problem.php?cid=1803&pid=13 题意:给出一个n,接下来一行给出n个数.才开始所有数为0,每次操作可以选一个区间[l ...

  3. 【upc】2020年秋季组队训练赛第十二场J Greedy Termite | 删点线段树

    状态 题目描述 There are n wooden rods vertically placed over a horizontal line. The rods are numbered 1 th ...

  4. 「团队训练赛」The 14th Jilin Provincial Collegiate Programming Contest「ABCEFGJLM」

    The 14th Jilin Provincial Collegiate Programming Contest A. Chord 题目描述: 给出C, C#, D, D#, E, F, F#, G, ...

  5. 「团队训练赛」2021 Jiangsu Collegiate Programming Contest题解

    A - Spring Couplets 题目描述: 写春联,满足所需的平仄关系 如果上联的一个字是平的,那下联对应的字必须是仄的 相同的,如果上联的一个字是仄的,那下联对应的字必须是平的 而且上联的最 ...

  6. 中石油训练赛 - Plan B(点双缩点+树形dp)

    题目大意:给出一张 n 个点 m 条边的无向连通图,现在有某些点被标记了,问能否通过删除某个未被标记的点,使得删除该点后的数个互不相交的连通块中,至少存在一个联通块中不含有被标记的点 题目分析:首先不 ...

  7. 中石油训练赛 - Russian Dolls on the Christmas Tree(树上启发式合并/主席树)

    题目链接:点击查看 题目大意:给出一棵 n 个节点的树,以点 1 为根,现在对于每个节点作为根的子树求解:子树中有多少个编号不相交的连续子段,如:1 2 4 5 7,共有三个连续的段,分别为 [ 1 ...

  8. 【2019浙江省赛 - A】Vertices in the Pocket(权值线段树下二分,图,思维)

    题干: DreamGrid has just found an undirected simple graph with  vertices and no edges (that's to say, ...

  9. 第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(南京)J Just Another Game of Stones ——线段树区间更新小于x的数

    This way 题意: 给你n个数,每次有两种操作: 1 l r v 表示a[i]=max(a[i],v)[l<=i<=r] 2 l r v 简单来说就是问你v和a[i](l<=i ...

最新文章

  1. linux设置默认时区,关于linux:如何修改-Linux-默认时区
  2. python关键字是什么颜色,python – Matplotlib:如果使用关键字sym,则使用Boxplot异常值颜色更改...
  3. 二叉树、二叉排序树及其遍历
  4. JavaScript实现k-Means算法(附完整源码)
  5. hadoop2 5个环境配置文件
  6. 荣耀30会升级鸿蒙吗,荣耀手机也能升级!第三批鸿蒙手机升级名单大曝光:全球第三稳了...
  7. linux shell之pushd、popd、dirs
  8. 保持学习,从这几个公众号开始!
  9. linux目录结果说明,Linux目录结构及文件说明
  10. vue打包代码反编译_Android逆向反编译代码注入APK过程思路分析
  11. Geatpy自定义初始种群
  12. Active Directory Get User's groups using LDAP
  13. 指定的網域的名稱或安全性識別碼(用磁碟映像檔部署的電腦無法加入AD網域 )...
  14. 乐鑫Esp32学习之旅15 认识本地离线语音唤醒识别框架 esp-skainet ,实现较低成本的硬件语音本地识别控制。
  15. 多源多目标统计信息融合 目标跟踪 信息融合 贝叶斯滤波总结
  16. 在线编辑Word——插入内容控件
  17. 拍牌神器是怎样炼成的(一)--- 键鼠模拟之WinAPI
  18. 车载网络技术——CAN总线基础
  19. 【uniapp】微信小程序微信授权新旧解决方案
  20. 解决IIS+PHP出现的“500 - 内部服务器错误”

热门文章

  1. 企业自建私有云-openstack-基础环境搭建
  2. 大数据工程师面试题(附答案)
  3. 领导吐槽辛苦三个月培养的程序员,骂几句就离职了!
  4. Three.js的学习之路(一丶创建项目/画出第一个3D模型)
  5. 广东人爱食的住家菜【香煎咸鱼】【咸鱼白菜】
  6. 信息系统项目管理师章节重点(10)项目人力资源管理
  7. html 绘制甘特图,Markdown绘制甘特图教程
  8. Iptables包过滤型防火墙--马哥运维笔记
  9. 网络安全技术第七章——防火墙技术概述及应用(包过滤防火墙 、代理防火墙、状态检测防火墙、分布式防火墙)
  10. 如何开发旅游商城系统?