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. ...
随机推荐
- 用Blackbox Exporter to Monitor web和端口
1.按照exporter .wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.12.0/blackbo ...
- MySQL_数据库命令
Mysql基础命令 开启MySQL服务:net start mysql 关闭MySQL服务:net stop musql 进入mysql:mysql -h localhost -u root -p 1 ...
- SpringBoot项目在IDEA中以jar方式部署
1.在pom.xml下添加如下插件 这个插件可以在项目打包成jar包后,通过java -jar运行 <build> <plugins> <plugin> <g ...
- 【转帖】.NET的一点历史故事:Novell的崩溃和Xamarin的重生
.NET的一点历史故事:Novell的崩溃和Xamarin的重生 https://blog.csdn.net/sD7O95O/article/details/78096502 学习安装 mono 时了 ...
- PAT A1011 World Cup Betting(20)
AC代码 #include <cstdio> #include <algorithm> const int max_n = 3; using namespace std; /* ...
- selenium登录豆瓣网
登录流程: 实例化一个driver,然后driver.get()发送请求 最重要的:切换iframe子框架,因为豆瓣的网页中的登录那部分是一个ifrme,必须切换才能寻找到对应元素 利用seleniu ...
- C#常见面试题(一)——try-catch-finally-return
面试常会被问及try-catch-finally,现在做一下总结: 第一.不管有没有出现异常,finally块中代码都会执行. 第二.finally 代码块中不能有return. 第三.如果try 或 ...
- 老贾的第二天(git常用命令)
git init #创建一个本地的仓库 **git add test.txt #指定文件添加 ***git add . #当前文件夹下所有内容 添加到暂存区 ***git commit -m &quo ...
- B2B、B2C、C2C、O2O分别是什么意思?
1.B2B 是指进行电子商务交易的供需双方都是商家(或企业.公司),她(他)们使用了互联网的技术或各种商务网络平台,完成商务交易的过程.电子商务是现代 B2B marketing的一种具体主要的表现形 ...
- 并不对劲的复健训练-bzoj5339:loj2578:p4593:[TJOI2018]教科书般的亵渎
题目大意 题目链接 题解 先将\(a\)排序. \(k\)看上去等于怪的血量连续段的个数,但是要注意当存在\(a_i+1=a_{i+1}\)时,虽然它们之间的连续段为空,但是还要算上:而当\(a_m= ...