Codeforces Round #374 (Div. 2)【A,B,C】
= =C题这种DP打的少吧,记得以前最短路分层图打过这样子的,然后比赛前半个小时才恍然大雾。。。然后瞎几把还打错了,还好A,B手速快。。上分了;
A题:
计算B的连续个数的组数,每组的连续个数;
水题;
#include <iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std;
char s[110];
int a[110];
int main()
{
int n;
scanf("%d",&n);
scanf("%s",s);
int num=0;
int flag=0;
memset(a,0,sizeof(a));
for(int i=0;i<n;i++)
{
if(s[i]=='B')
{
if(flag)
{
a[num]++;
}
else
{
a[++num]++;
flag=1;
}
}
else
{
flag=0;
}
}
printf("%d\n",num);
for(int i=1;i<=num;i++)
printf("%d ",a[i]);
return 0;
}
B题:
求最少开锁,最晚开锁;= =最后一个是密码;
这题纯暴力模拟,水;
#include <iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std;
/*
*/
char s[110][110];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=1;i<=n+1;i++)
{
scanf("%s",s[i]);
}
int temp=strlen(s[n+1]);
int mini=0;
int mimi=0;
for(int i=1;i<=n;i++)
{
int x=strlen(s[i]);
if(x<temp)
mini++;
if(x<=temp&&strcmp(s[i],s[n+1])!=0)
mimi++;
}
int ans1=0;
if(mini)
{
for(int i=1;i<=mini;i++)
{
if(i%k==0)
ans1+=5;
ans1++;
}
}
printf("%d ",ans1+1);
int ans2=0;
if(mimi)
{
for(int i=1;i<=mimi;i++)
{
if(i%k==0)
ans2+=5;
ans2++;
}
}
printf("%d\n",ans2+1);
return 0;
}
C题:
求1-n的路径长度<=T范围内,最多能经过几个点;
思路:
dp[i][j]代表到达 i 经 过 j 个点的最小花费;
然后BFS每个可到达,里面写个小DP;
//注意vis数组开bool,不知道不开会不会MLE,还有图的话最好用链表模拟;
#include <bits/stdc++.h>
using namespace std;
//dp[i][j]代表到达第i个结点,经过j个结点的最短时间;
typedef pair<int,int> PP;
const int INF=0x3f3f3f3f;
int dp[5001][5001];
bool vis[5001][5001];
int pre[5001][5001];
int n,m,T;
int i,j,k;
int u,v,w;
vector<PP>ma[5001];
queue<PP>q;
void bfs()
{
vis[1][1]=true;
dp[1][1]=0;
q.push({1,1});
while(!q.empty())
{
PP u=q.front();q.pop();
int x=u.first;
int y=u.second;
vis[x][y]=false;
v=ma[x].size();
for(i=0;i<v;i++)
{
int xx=ma[x][i].first;
int co=ma[x][i].second;
if(dp[x][y]+co>T)
continue;
if(dp[xx][y+1]>dp[x][y]+co)
{
dp[xx][y+1]=dp[x][y]+co;
pre[xx][y+1]=x;
if(vis[xx][y+1]) continue;
vis[xx][y+1]=true;
q.push({xx,y+1});
}
}
}
}
void print()
{
vector<int>res;
res.push_back(n);
while(pre[n][j])
{
res.push_back(pre[n][j]);
n=pre[n][j];
j--;
}
int ans=res.size();
printf("%d\n",ans);
for(i=ans-1;i>=0;i--)
{
printf("%d ",res[i]);
}
}
int main()
{
memset(dp,INF,sizeof(dp));
scanf("%d%d%d",&n,&m,&T);
for(i=1;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&w);
ma[u].push_back({v,w});
}
bfs();
for(i=n;i>=1;i--)
{
if(dp[n][i]<=T)
{
j=i;
break;
}
}
print();
return 0;
}
Codeforces Round #374 (Div. 2)【A,B,C】的更多相关文章
- Codeforces Round #374 (Div. 2) A , B , C 水,水,拓扑dp
A. One-dimensional Japanese Crossword time limit per test 1 second memory limit per test 256 megabyt ...
- Codeforces Round #646 (Div. 2)【C. Game On Leaves 题解】
题意分析 关于这道题,意思就是两个人摘叶子,谁最后摘到编号为x的谁就赢了.既然是叶子,说明其最多只有一个分支,由于题目上说了是无向图,那就是度数小于等于的节点.也就是一步步移除度数小于等于的节点,直到 ...
- Codeforces Round #443 (Div. 2) 【A、B、C、D】
Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...
- Codeforces Round #436 (Div. 2)【A、B、C、D、E】
Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...
- Codeforces Round #435 (Div. 2)【A、B、C、D】
//在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...
- Codeforces Round #434 (Div. 2)【A、B、C、D】
Codeforces Round #434 (Div. 2) codeforces 858A. k-rounding[水] 题意:已知n和k,求n的最小倍数x,要求x后缀至少有k个0. 题解:答案就是 ...
- Codeforces Round #441 (Div. 2)【A、B、C、D】
Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...
- Codeforces Round #440 (Div. 2)【A、B、C、E】
Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...
- Codeforces Round #439 (Div. 2)【A、B、C、E】
Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...
随机推荐
- SPOJ - GSS1&&GSS3
GSS1 #include<cstdio> #include<iostream> #define lc k<<1 #define rc k<<1|1 u ...
- Hibernate中的事务处理流程详解
一.Hibernate操作的基本流程 使用 Hibernate 进行数据持久化操作,通常有如下步骤: 1.编写持久化类: POJO + 映射文件 2.获取 Configuration 对象 3.获取 ...
- 2018-11-13-常用模块1 (time random os sys)
1.时间模块 time 2.随机数模块 random 3.与操作系统交互模块 os 4.系统模块 sys 在我们真正开始学习之前我们先解决下面几个问题,打好学习模块的小基础,以便更好的学习模块. (1 ...
- memcached和一致性hash算法
1 一致性hash算法的一致性 这里的一致性指的是该算法可以保持memcached和数据库中的数据的一致性. 2 什么是一致性hash算法 2.1 为什么需要一致性hash算法 现在有大量的key v ...
- 杭电 2553 N皇后问题
http://acm.hdu.edu.cn/showproblem.php?pid=2553 N皇后问题 Time Limit: 2000/1000 MS (Java/Others) Memor ...
- python错误提示“TabError: inconsistent use of tabs and spaces in indentation”
在遍历打印10以内的奇数是出现“TabError: inconsistent use of tabs and spaces in indentation”的错误提示: 代码如下: 第一感觉没什么错误, ...
- CSS3学习笔记(2)—左右跳动的红心
还在为无法表达内心澎湃的心情而着急吗?还在为制作跳动的心而烦恼吗?哈哈,今天我就把代码全部奉上,为你们追妹子添点贡献,下面来看最终的动态效果(事先说明一下:我用的截屏gif制作软件是绿色版的,所以gi ...
- HackerRank leonardo-and-lucky-numbers —— 模线性方程的通解
题目链接:https://vjudge.net/problem/HackerRank-leonardo-and-lucky-numbers 题解: 1.根据扩展欧几里得:7*x + 4*y = gcd ...
- Codeforces Round #303 (Div. 2) D. Queue —— 贪心
题目链接:http://codeforces.com/problemset/problem/545/D 题解: 问经过调整,最多能使多少个人满意. 首先是排序,然后策略是:如果这个人对等待时间满意,则 ...
- jinja 多值合并
示例 {% for node in groups["db"] %} {{ node | join("") }}:5672 {% if not loop.last ...