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. jQuery 菜单

  2. jQuery.serialize() 函数详解////////////z

    serialize()函数用于序列化一组表单元素,将表单内容编码为用于提交的字符串. serialize()函数常用于将表单内容序列化,以便用于AJAX提交. 该函数主要根据用于提交的有效表单控件的n ...

  3. 4. 什么是AJAX

    术语Ajax用来描述一组技术,它使浏览器可以为用户提供更为自然的浏览体验.在Ajax之前,Web站点强制用户进入提交/等待/重新显示范例,用户的动作总是与服务器的“思考时间”同步.Ajax提供与服务器 ...

  4. 计算ScrollView的当前页面

    //每页宽度 CGFloat pageWidth = sender.frame.size.width; //根据当前的坐标与页宽计算当前页码 int currentPage = floor((send ...

  5. paper 120:计算距离矩阵的函数的pdist和pdist2函数

    matlab中自带的计算距离矩阵的函数有两个pdist和pdist2.前者计算一个向量自身的距离矩阵,后者计算两个向量之间的距离矩阵.基本调用形式如下: D = pdist(X) D = pdist2 ...

  6. java compiler level does not match the version of the installed java project facet

    Java compiler level does not match the version of the installed java project facet错误的解决 因工作的关系,Eclip ...

  7. 干货——myeclipse快捷键

    好了废话不多说.先上快捷键快捷键 alt    alt+           返回操作记录的上一步    alt+        返回操作记录的下一步    alt+shift+o        同一 ...

  8. Java数据结构与算法之---求两个数的最大公约数(欧几里得算法)

    一个简单的小算法来获取两个数的最大公约数, public class Test { public static void main(String[] args) { long result = gcd ...

  9. js,jquery获取浏览器信息

    1.js获取: 查看:window.navigator 2.jQuery获取: chrome firefox 推荐使用navigator获取userAgent然后去正则匹配 参考匹配规则:http:/ ...

  10. JavaScriptCore 使用

    JavaScriptCore JavaScriptCore是webkit的一个重要组成部分,主要是对JS进行解析和提供执行环境.代码是开源的,可以下下来看看(源码).iOS7后苹果在iPhone平台推 ...