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 ...
随机推荐
- jQuery瀑布流
- 非常简单的数据,支持excel表格下载功能
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...
- 修改后的CopyFile类
这是修改后的CopyFile类,前面那个类有局限性,它不能复制大文件 这是我第一次写成一个能够实际应用的类,感谢博主们的无私奉献,感谢SeayXu老师的提点 但是这个类也并不是完美无缺,它复制文件没有 ...
- 初次了解的Java多线程
0.1熟悉多线程 多线程(英语:multithreading),是指从软件或者硬件上实现多个线程并发执行的技术.具有多线程能力的计算机因有硬件支持而能够在同一时间执行多于一个线程,进而提升整体处理性能 ...
- ExtJS6 自适应浏览器窗口大小
ExtJS6官方文档推荐使用Ext.on.做一个小例子,创建一个Panel显示在页面上,使它的大小随浏览器变化,自适应浏览器窗口大小. html:增加一个css样式给Panel加上红色border. ...
- 详解:数据库名、实例名、ORACLE_SID、数据库域名、全局数据库名、服务名及手工脚本创建oracle数据库
数据库名.实例名.数据库域名.全局数据库名.服务名 , 这是几个令很多初学者容易混淆的概念.相信很多初学者都与我一样被标题上这些个概念搞得一头雾水.我们现在就来把它们弄个明白. 一.数据库名 什么是数 ...
- C语言 04 进制
%d 或者%i 十进制 %c 输出字符 %p 输出地址 %f 输出小数 %o 八进制 %x 十六进制 一个int类型变量占4字节,占32bit(位) 例子:十进制 int=12 转二进制 0000 ...
- jqGrid subGrid配置 如何首次加载动态展开所有的子表格
有时候需求需要默认加载表格的时候把子表格的数据也显示出来,经过研究相关SubGrids API配置如下: 属性 类型 描述 默认值 subGrid boolean 设置为true启用子表格.如果启用子 ...
- maven插件
sql-maven-plugin: http://www.mojohaus.org/sql-maven-plugin/ 常用插件: http://www.trinea.cn/android/maven ...
- 分表的一个记录---Ruby
sql1=" UPDATE user_red_info_"sql2=" SET status = '#{status}', update_time = '#{update ...