Summer training #7
B:读懂题意模拟
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-6
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int n;
int m1,m2,y1,y2;
cin >> n;
double ans;
while(n--)
{
scanf("%d %d %d %d",&m1,&y1,&m2,&y2);
//cout<< a << b << c << d<<endl;
if(y1==y2)
ans=(m2-m1)/2.0/(-m1)+EPS;
else
ans=0.5+(y2-y1-)+1.0/*(m2-)+EPS;
printf("%.4lf\n",ans);
}
return ;
}
C:给你一个起点和终点 每个点有补给但是只能拿一次 每条路有经过的cost 问你能不能到终点 能的话最少cost多少 DFS + 剪枝
(对于一个走过点k,如果有必要再走一次,那么一定是走过k后在k点的最大弹药数增加了.否则一定没有必要再走. 记录经过每个点的最大弹药数,对dfs进行剪枝.)
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
map<string, int> pos;
struct Edge {
int v, c, next;
} edge[];
int head[], cnt;
int vis[], amm[], aim[],sum[];
int cs, n, m, ans;
string s, t; void addedge (int u, int v, int c) {
edge[++cnt].v = v, edge[cnt].c = c;
edge[cnt].next = head[u];
head[u] = cnt;
}
void dfs (int x, int s, int k) {
if(k>=ans) return;
if (aim[x]) {
ans = min (ans, k);
return ;
}
if (!vis[x]) s += amm[x], vis[x] = ;
if(vis[x]&&sum[x]>=s) return;
sum[x]=max(sum[x],s);
for (int i = head[x]; i; i = edge[i].next) {
int v = edge[i].v, c = edge[i].c;
if (s >= c) dfs (v, s - c, k + c);
}
vis[x] = ;
}
int main() {
scanf ("%d", &cs);
while (cs--) {
pos.clear();
memset (head, , sizeof head);
memset(sum,,sizeof sum);
memset(vis,,sizeof vis);
cnt = , ans = 0x7fffffff;
scanf ("%d %d", &n, &m);
for (int i = ; i <= n; i++) {
cin >> s;
pos[s] = i;
cin >> amm[i] >> s;
if (s[] == ‘y‘) aim[i] = ;
else aim[i] = ;
}
for (int i = , x; i <= m; i++) {
cin >> s >> t >> x;
int u = pos[s], v = pos[t];
addedge (u, v, x);
addedge (v, u, x);
}
dfs (, , );
if (ans != 0x7fffffff) printf ("%d\n", ans);
else puts ("No safe path");
}
}
D
E:如果有 就先去掉特殊的两个 然后DFS
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-6
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
int num[];
int flag=;
void dfs(int number)
{
if(number==||flag==)
{
flag=;
return ;
}
for(int i=;i<=;i++)
{
if(num[i]>=&&num[i+]>=&&num[i+]>=)
{
num[i]-=;
num[i+]-=;
num[i+]-=;
dfs(number+);
num[i]+=;
num[i+]+=;
num[i+]+=;
}
}
for(int i=;i<=;i++)
{
if(num[i]>=)
{
num[i]-=;
dfs(number+);
num[i]+=;
}
}
}
void init()
{
for(int i=;i<=;i++)
{
if(num[i]<)
continue;
num[i]-=;
dfs();
num[i]+=;
if(flag==)
break;
}
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int n;
cin >> n;
while(n--)
{
flag=;
mem(num,);
int a[];
for(int i=;i<=;i++)
{
scanf("%d",&a[i]);
num[a[i]]++;
}
init();
if(flag==)
printf("Vulnerable\n");
else
printf("Immune\n");
}
return ;
}
F:BFS 注意!!一次outbreak只能在BFS中的每个点发生一次
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-6
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
char s[][];
char visit[][];
queue<pair<int,int> > que;
int dir[][];
int n,m;
void bfs()
{
for(int i=;i<=;i++)
mem(visit[i],);
pair<int,int> a;
while(!que.empty())
{
a=que.front();
que.pop();
int r=a.first;
int c=a.second;
if(s[r][c]=='D')
{
for(int i=;i<;i++)
{
int r1=r+dir[i][];
int c1=c+dir[i][];
if(r1>=&&r1<n&&c1>=&&c1<m&&s[r1][c1]!='X')
{
if(s[r1][c1]=='D'&&!visit[r1][c1])
{
pair<int,int> b;
b.first=r1,b.second=c1;
que.push(b);
visit[r1][c1]=;
}
else if(s[r1][c1]>='A'&&s[r1][c1]<'D')
{
s[r1][c1]=s[r1][c1]+;
}
}
}
visit[r][c]=;
}
else if(s[r][c]>='A'&&s[r][c]<'D')
{
s[r][c]=s[r][c]+;
}
}
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
dir[][]=-,dir[][]=;
dir[][]=,dir[][]=;
dir[][]=,dir[][]=;
dir[][]=,dir[][]=-;
int t;
cin >> t;
while(t--)
{
for(int i=;i<=;i++)
mem(visit[i],);
int r,c;
scanf("%d %d",&m,&n);
for(int i=;i<n;i++)
scanf("%s",s[i]);
int time;
scanf("%d",&time);
while(time--)
{
scanf("%d %d",&c,&r);
pair<int,int> a;
a.first=r,a.second=c;
que.push(a);
bfs();
/*for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
printf("%c",s[i][j]);
printf("\n");
}
cout<<endl;*/
}
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
printf("%c",s[i][j]);
printf("\n");
}
}
return ;
}
G:水
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-8
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
int a[];
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int n;
cin >> n;
while(n--)
{
for(int i=;i<;i++)
cin>>a[i];
for(int i=;i>;i--)
{
if(i!=)
a[i-]+=a[i]/;
a[i]=a[i]%;
}
cout<<a[];
for(int i=;i<;i++)
cout<<" "<<a[i];
cout<<endl;
}
return ;
}
F:以分号为界 每个一行 按照题意输出 substr的应用
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-8
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
string a,b;
int now=;
int pop=;
void doit()
{
int cur=;
string ans;
for(int i=;i<b.size();i++)
{
if(b[i]==';')
{
ans=b.substr(cur,i-cur+);
if(pop==)
printf("%d: ",now-);
else
printf("%d: ",now);
cout<<ans<<endl;
cur=i+;
}
}
b=b.substr(cur,b.size()-cur+);
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int t;
cin >> t;
now=;
b=a="";
while(getline(cin,a))
{
now++;
if(a=="END OF CASE")
{
pop=;
now=;
b="";
continue;
}
b+=a;
doit();
}
return ;
}
J:
Summer training #7的更多相关文章
- hdu 4946 2014 Multi-University Training Contest 8
Area of Mushroom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 2016 Multi-University Training Contests
2016 Multi-University Training Contest 1 2016 Multi-University Training Contest 2 2016 Multi-Univers ...
- 2016 Multi-University Training Contest 2 D. Differencia
Differencia Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 2016 Multi-University Training Contest 1 G. Rigid Frameworks
Rigid Frameworks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- The Solution of UESTC 2016 Summer Training #1 Div.2 Problem C
Link http://acm.hust.edu.cn/vjudge/contest/121539#problem/C Description standard input/output After ...
- 2012 Multi-University Training Contest 9 / hdu4389
2012 Multi-University Training Contest 9 / hdu4389 打巨表,实为数位dp 还不太懂 先这样放着.. 对于打表,当然我们不能直接打,这里有技巧.我们可以 ...
- 2014 Multi-University Training Contest 9#11
2014 Multi-University Training Contest 9#11 Killing MonstersTime Limit: 2000/1000 MS (Java/Others) ...
- 2014 Multi-University Training Contest 9#6
2014 Multi-University Training Contest 9#6 Fast Matrix CalculationTime Limit: 2000/1000 MS (Java/Oth ...
- 2016 Multi-University Training Contest 1
8/11 2016 Multi-University Training Contest 1 官方题解 老年选手历险记 最小生成树+线性期望 A Abandoned country(BH) 题意: 1. ...
随机推荐
- python-linux-集群nginx
一命令基本格式 ----cd ~ 家 ----cd / 根 ---cd .. 上级 ----pwd 当前路径 ----ls -l -a -h ----权限rwxrwxrwx 755 二文件 ...
- git配置过程中fatal:拒绝合并无关的历史
首先将远程仓库和本地仓库关联起来: git branch --set-upstream-to=origin/master master 然后使用git pull整合远程仓库和本地仓库, git pul ...
- Spring Cloud health节点通过注册中心扫描状态的简单实现
package com.zjs.web; import com.netflix.appinfo.InstanceInfo; import com.zjs.FallbackApiApplication; ...
- 深入理解C语言-二级指针三种内存模型
二级指针相对于一级指针,显得更难,难在于指针和数组的混合,定义不同类型的二级指针,在使用的时候有着很大的区别 第一种内存模型char *arr[] 若有如下定义 char *arr[] = {&quo ...
- rtsp学习参考资料1
转载于:http://itindex.net/detail/51966-%E6%B5%B7%E5%BA%B7-rtsp-%E5%AE%A2%E6%88%B7%E7%AB%AF 海康相机RTSP连接代码 ...
- VMware虚拟机下安装CentOS 6.10并配置访问外网
VMware安装包以及CentOS 6.5安装包 链接:https://pan.baidu.com/s/1wQi5GSgp4klXhtd84aoMSA 提取码:9l5y 链接:https://pan. ...
- 解决连接HIS连接不上数据库的问题
运行程序单步运行,设置断点 配置HIS中的 GetDataBaseInfo类,将与本机无关的配置函数全部删除,(按照DMHospital.ini文件来对照修改),如下图: 往数据库中所创建的表中添加数 ...
- 前缀和&二维前缀和
我们知道,数组上的前缀和S[i]=S[i-1]+a[i] 那么,怎样求二维前缀和呢? 二维前缀和: 绿色点的前缀和就是黄色.红色.灰色和绿色的点权和 怎样计算? s[i][j]=s[i-1][j]+s ...
- django 中 null=True 和 blank=True的区别!
null 是针对数据库而言,如果 null=True, 表示数据库的该字段可以为空,即在Null字段显示为YES. blank 是针对表单的,如果 blank=True,表示你的前端表单填写该字段的时 ...
- spark内核篇-任务调度机制
在生产环境中,spark 部署方式一般都是 yarn-cluster 模式,本文针对该模式进行讲解,当然大体思路也适用于其他模式 基础概念 一个 spark 应用包含 job.stage.task 三 ...