Codeforces Round #267 (Div. 2)
A
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int main()
{
int n,i,j;
int ans = ;
cin>>n;
for(i = ; i <= n; i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(y-x>=) ans++;
}
cout<<ans<<endl;
return ;
}
B
还以为是间接的朋友,写复杂了,没想到那么简单。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 1010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int a[N];
int fa[N];
int r[N];
int find(int x)
{
if(x!=fa[x])
{
fa[x] = find(fa[x]);
return fa[x];
}
return x;
}
int main()
{
int n,m,k,i,j;
cin>>n>>m>>k;
for(i = ;i <= m+; i++) {fa[i] = i;r[i] = ;}
for(i = ; i <= m+; i++)
scanf("%d",&a[i]);
int ans = ;
for(i = ; i <= m; i++)
{
int cnt = ;
for(int g = ; g < n ;g++)
if((a[m+]&(<<g))!=(a[i]&(<<g))) cnt++;
if(cnt<=k) ans++;
}
// for(i = 1; i <= m+1; i++)
// for(j = 1; j <= m+1; j++)
// {
// if(i==j) continue;
// int cnt = 0;
// for(int g = 0 ; g < n ;g++)
// if((i&(1<<g))!=(i&(1<<g))) cnt++;
// if(cnt<=k)
// {
// int tx = find(i);
// int ty = find(j);
// if(tx!=ty)
// {
// fa[tx] = ty;
// r[tx]+=r[ty];
// }
// }
// }
// int kk = find(m+1);
cout<<ans<<endl;
return ;
}
C
简单dp
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 5010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int a[N];
LL dp[N][N];
LL sum[N];
int main()
{
int n,m,k,i,j;
cin>>n>>m>>k;
for(i = ; i <= n; i++)
{
scanf("%d",&a[i]);
sum[i] = sum[i-]+a[i];
}
for(i = m; i <= n ;i++)
{
for(j = ; j <= k; j++)
dp[i][j] = max(dp[i-m][j-]+sum[i]-sum[i-m],dp[i-][j]);
}
cout<<dp[n][k]<<endl;
return ;
}
D
tarjan缩点+dfs
dfs的时候少写了else里面的内容。。一直wa到结束
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define N 500010
#define M 500010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct node
{
int u,v,next,w;
} edge[M];
int t,low[N],pre[N],sccno[N],head[N],scc,dep,vis[N],dis[N];
int dd1[N],dd2[N];
int dp[N];
int num[N],de[N];
vector<int>cd[N];
void init()
{
t = ;
memset(head,-,sizeof(head));
}
void add(int u,int v)
{
edge[t].u =u;
edge[t].v = v;
edge[t].next = head[u];
head[u] = t++;
}
stack<int>s;
void dfs(int u)
{
low[u] = pre[u] = ++dep;
s.push(u);
for(int i = head[u] ; i!=- ; i = edge[i].next)
{
int v = edge[i].v;
if(!pre[v])
{
dfs(v);
low[u] = min(low[u],low[v]);
}
else if(!sccno[v])
low[u] = min(low[u],pre[v]);
}
if(low[u]==pre[u])
{
scc++;
int minz = INF,sum=INF;
for(;;)
{
int x = s.top();
s.pop();
if(minz>num[x])
{
minz = num[x];
sum = dp[x];
}
else if(minz==num[x]) sum = min(dp[x],sum);
sccno[x] = scc;
if(x==u)break;
}
dd1[scc] = minz;
dd2[scc] = sum; }
}
void find_scc(int n)
{
scc=;
dep=;
memset(low,,sizeof(low));
memset(pre,,sizeof(pre));
memset(sccno,,sizeof(sccno));
for(int i = ; i <= n ; i++)
if(!pre[i])
dfs(i);
}
map<string,int>f;
vector<int>ed[N];
char s1[N],s2[N];
int a[N];
int judge(char *str)
{
int i,k;
k= strlen(str);
int cnt = ;
for(i = ; i < k; i++)
if(str[i]=='R')
cnt++;
return cnt;
}
int ddfs(int u)
{
int i,j;
for(i = ; i< ed[u].size() ; i++)
{
int v = ed[u][i];
if(!vis[v])
{
vis[v] = ;
int ss = ddfs(v);
if(dd1[u]>=ss)
{
if(dd1[u]==ss)
dd2[u] = min(dd2[u],dd2[v]);
else dd2[u] = dd2[v];
dd1[u] = ss;
}
}
else if(dd1[u]>=dd1[v])
{
if(dd1[u]==dd1[v]) dd2[u] = min(dd2[u],dd2[v]);
else dd2[u] = dd2[v];
dd1[u] = dd1[v];
}
}
return dd1[u];
}
int main()
{
init();
int m,i,j,n;
scanf("%d",&m);
int g = ;
for(i = ; i <= m ; i++)
{
scanf("%s",s1);
int len = strlen(s1);
for(j = ; j < len; j++) if(s1[j]>='a'&&s1[j]<='z') s1[j]-=;
if(!f[s1])
{
a[i] = ++g;
f[s1] = g;
}
else a[i] = f[s1];
num[a[i]] = judge(s1);
dp[a[i]] = len;
}
scanf("%d",&n);
for( i = ; i <= n ; i++)
{
int u,v;
scanf("%s%s",s1,s2);
int len1 =strlen(s1) ,len2 = strlen(s2);
for(j = ; j < len1; j++) if(s1[j]>='a'&&s1[j]<='z') s1[j]-=;
for(j = ; j < len2; j++) if(s2[j]>='a'&&s2[j]<='z') s2[j]-=;
if(!f[s1])
{
u = ++g;
f[s1] = g;
}
else u = f[s1];
if(!f[s2])
{
v = ++g;
f[s2] = g;
}
else v = f[s2];
add(u,v);
num[u] = judge(s1);
num[v] = judge(s2);
dp[u] = len1;
dp[v] = len2;
cd[u].push_back(v);
}
find_scc(g);
for(i = ; i <= g; i++)
{
int u = sccno[i];
for(j = ;j < cd[i].size() ; j++)
{
int v = sccno[cd[i][j]];
if(v==u) continue;
ed[u].push_back(v);
de[v] = ;
}
}
memset(vis,,sizeof(vis));
for(i = ; i <= scc; i++)
{
if(!de[i])
{
vis[i] = ;
ddfs(i);
}
}
LL ans = ,sum=;
for(i = ; i<= m; i++)
{
int u = sccno[a[i]];
//cout<<u<<" "<<dd2[u]<<endl;
ans+=dd1[u];
sum+=dd2[u];
}
cout<<ans<<" "<<sum<<endl;
return ;
}
Codeforces Round #267 (Div. 2)的更多相关文章
- 01背包 Codeforces Round #267 (Div. 2) C. George and Job
题目传送门 /* 题意:选择k个m长的区间,使得总和最大 01背包:dp[i][j] 表示在i的位置选或不选[i-m+1, i]这个区间,当它是第j个区间. 01背包思想,状态转移方程:dp[i][j ...
- Codeforces Round #267 (Div. 2) C. George and Job(DP)补题
Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...
- Codeforces Round #267 Div.2 D Fedor and Essay -- 强连通 DFS
题意:给一篇文章,再给一些单词替换关系a b,表示单词a可被b替换,可多次替换,问最后把这篇文章替换后(或不替换)能达到的最小的'r'的个数是多少,如果'r'的个数相等,那么尽量是文章最短. 解法:易 ...
- Codeforces Round #267 (Div. 2) C. George and Job DP
C. George and Job The new ITone 6 has been released ...
- Codeforces Round #267 (Div. 2) A
题目: A. George and Accommodation time limit per test 1 second memory limit per test 256 megabytes inp ...
- Codeforces Round #267 (Div. 2)D(DFS+单词hash+简单DP)
D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #267 (Div. 2) D. Fedor and Essay tarjan缩点
D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #267 (Div. 2) B. Fedor and New Game【位运算/给你m+1个数让你判断所给数的二进制形式与第m+1个数不相同的位数是不是小于等于k,是的话就累计起来】
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play ...
- Codeforces Round #267 (Div. 2) B. Fedor and New Game
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play ...
随机推荐
- sql 默认id为1000
创建索引: alter table resource AUTO_INCREMENT=1000; //id默认自增为1000:
- js事件监听/鼠标滚轮/行为/冒泡/键盘的兼容性写法
addEvent:function(el,type,fn,capture) { if (window.addEventListener) { if (type === "mousewheel ...
- java布局学习 (二)
前文中介绍了FlowLayout和BorderLayout 本文我们将会继续介绍java中的布局方式 (3)GridLayout 网格布局 这种布局会将整个容器划分成M行*N列的网格. 如下图: ...
- iphone H5视频行内播放(禁止全屏播放)
一般用户都知道,ios在网页点击视频播放时,视频会弹出全屏播放框. video标签的playsinline.webkit-playsinline标记根本就不会起作用. 还有传闻说对于没有声音的视频不会 ...
- 用node.js给图片加水印
一.准备工作: 首先,确保你本地已经安装好了node环境.然后,我们进行图像编辑操作需要用到一个Node.js的库:images.这个库的地址是:https://github.com/zhangyua ...
- 用Swift语言做App开发之单元测试
作为一个有质量保障的应用程序,当然少不了单元测试:Swift开发的App也亦如此,此文将以一个简单的实例来介绍Swift中的单元测试. 这里我们使用XCode模版自带的XCTest框架,此框架包含了一 ...
- Linux_用户级_常用命令(3):mkdir
Linux常用命令之mkdir 开篇语:懒是人类进步的源动力 本文原创,专为光荣之路公众号所有,欢迎转发,但转发请务必写出处! Linux常用命令第3集包含命令:mkdir (附赠tree命令,日期时 ...
- 设置button键隐藏文字text
新手的第一天,从最简单的view开始做起.首先先来做个最简单的button携带不可见文本,想要的时候,get它就行了. 编程的都知道,get .set方法,就不多介绍了. 创建一个类,MyButto ...
- 关于sql的关联排序
个人觉得对sql的玩转其实是sql中各种函数方法的理解的透彻. 原始数据表 要求查询的结果排序 其实刚看题目可能觉得要用group by但是再网下继续思考可能就没有思路了 但是如果你接触过over的试 ...
- iOS设计规范整理|汇总
来源 UI中国