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 ...
随机推荐
- SAP-ABAP系列 第一篇SAP简介
第一篇 SAP简介 SAP全名为System Application and Products in Data Processing.SAP目前是全世界排名第一的RP软件,号称“全球最大的企业管理解决 ...
- Android: 亲測解决模拟器启动慢的问题
1.首先在相应的sdk manager里面下载一个4.03以上的api. 这里我选择的是4.2.2 (api17) 2.选择里面的" Intel Hardware Accelerated E ...
- sanic官方文档解析之Deploying(部署)和Extension(扩展)
1,Deploying(部署) 通过内置的websocket可以很简单的部署sanic项目,之后通过实例sanic.Sanic,我们可以运行run这个方法通过接下来的关键字参数 host (defau ...
- Red Black Tree 红黑树 AVL trees 2-3 trees 2-3-4 trees B-trees Red-black trees Balanced search tree 平衡搜索树
小结: 1.红黑树:典型的用途是实现关联数组 2.旋转 当我们在对红黑树进行插入和删除等操作时,对树做了修改,那么可能会违背红黑树的性质.为了保持红黑树的性质,我们可以通过对树进行旋转,即修改树中某些 ...
- 阿里妈妈-RAP项目的实践(1)
在同事的推荐下,去了解了一下http://thx.github.io/RAP/study.html#,它是发现在前后端分离开发的神器 下面我们来简单上一组代码,来简单了解一下rap <!DOCT ...
- Machine Learning in Action(5) SVM算法
做机器学习的一定对支持向量机(support vector machine-SVM)颇为熟悉,因为在深度学习出现之前,SVM一直霸占着机器学习老大哥的位子.他的理论很优美,各种变种改进版本也很多,比如 ...
- object-c中的assign,retain,copy,atomic,nonatomic,readonly,readwrite以及strong,weak
assign:指定setter方法用简单的赋值,这是默认操作.你可以对标量类型(如int)使用这个属性.你可以想象一个float,它不是一个对象,所以它不能retain.copy.assign指定se ...
- hdu1198 Farm Irrigation —— dfs or 并查集
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1198 dfs: #include<cstdio>//hdu1198 dfs #includ ...
- BZOJ 3732 Network —— 最小生成树 + 倍增LCA
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3732 Description 给你N个点的无向图 (1 <= N <= 15, ...
- 程序移植到VS2010,编译成功但是无法启动lib文件
今天遇到的这个问题,是由于解决方案下有多个项目,其中包含生成库的项目,也有可执行程序的项目 解决方法:邮件解决方案,属性-通用属性-启动项目进行设置就OK了,我的是设置单启动项目为包含可执行程序的项目 ...