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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #267 Div.2 D Fedor and Essay -- 强连通 DFS

    题意:给一篇文章,再给一些单词替换关系a b,表示单词a可被b替换,可多次替换,问最后把这篇文章替换后(或不替换)能达到的最小的'r'的个数是多少,如果'r'的个数相等,那么尽量是文章最短. 解法:易 ...

  4. Codeforces Round #267 (Div. 2) C. George and Job DP

                                                  C. George and Job   The new ITone 6 has been released ...

  5. Codeforces Round #267 (Div. 2) A

    题目: A. George and Accommodation time limit per test 1 second memory limit per test 256 megabytes inp ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. [原创]java WEB学习笔记109:Spring学习---spring中事物管理

    博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱好 ...

  2. Ajax UI方面的处理方式

    一种方式: 从远程直接获取HTML加载到本地 第二种方式从远程获取JSON,到本地使用JS处理数据. var html = "<table cellspacing=\"0\& ...

  3. LinQ 简单使用

    LinQ: 1.LinQ to Sql类(NET Language Integrated Query (LINQ) ) LINQ定义了大约40个查询操作符,如select.from.in.where以 ...

  4. LCD接口(转载)

    LCD接口分类 1.   I8080接口,我觉得应该就是所谓的8080,通常会用在12864屏上面,且有内部sdram,不需要实时的刷新图片,速度有限制, 支持的数据宽度有8/9/16/18bit,接 ...

  5. XEN的启动信息输出到“Platform timer is 14.318MHz HPET”就暂停接收的解决办法

    使用Serial Over Lan(SOL)来双机调试 XEN,在 XEN 启动时,引导信息输出到以下这一句时,就不再发送调试信息了: ...(XEN) Intel machine check rep ...

  6. php生成随机密码的几种方法

    方法一: 1.在 33 – 126 中生成一个随机整数,如 35,2.将 35 转换成对应的ASCII码字符,如 35 对应 #3.重复以上 1.2 步骤 n 次,连接成 n 位的密码 该算法主要用到 ...

  7. 3.Git的诞生和其分布式的优点

    Git的诞生 省略了,喜欢的可以看百度. 分布式的优点 先说集中式版本控制系统,版本库是集中存放在中央服务器的,而干活的时候,用的都是自己的电脑,所以要先从中央服务器取得最新的版本,然后开始干活,干完 ...

  8. http错误码大全?

    响应码由三位十进制数字组成,它们出现在由HTTP服务器发送的响应的第一行.响应码分五种类型,由它们的第一位数字表示:1.1xx:信息,请求收到,继续处理2.2xx:成功,行为被成功地接受.理解和采纳3 ...

  9. swift跳转到Appstore

    //进入appstore中指定的应用 let str = NSString(format: "itms-apps://ax.itunes.apple.com/WebObjects/MZSto ...

  10. Linux命令的返回码列表

    转自:http://blog.chinaunix.net/uid-10347480-id-3263127.html 在 Linux 下,不管你是启动一个桌面程序也好,还是在控制台下运行命令,所有的程序 ...