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. 2.5 C#的数据类型

    在我们定义变量的时候需要使用数据类型,不同数据类型定义的变量,它的值的表现形式不同.比如整型主要表示整数,浮点型表示小数等等. C#中的数据类型有很多同C语言的相同,先学习一些简单的数据类型,其他的以 ...

  2. cef 介绍

    介绍 cef 是一个基于google chromiun的简单的框架. 它主要是作为一个内嵌浏览器嵌入到客户端应用程序中. 可以再 http://cefbuilds.com 下载最新的编译版本. 总体框 ...

  3. newtonsoft.json 序列化,反序列化

    public class Book { public string BookID { get; set; } public DateTime PublishDate { get; set; } pub ...

  4. activiti-5.15备份记录

    activiti-5.15用户手册翻译完成 源码下载地址:http://activiti.org/download.html在线浏览地址: http://www.mossle.com/docs/act ...

  5. PHP 将下划线命名 转换为 驼峰式命名

    function convertUnderline($str , $ucfirst = true) { $str = ucwords(str_replace('_', ' ', $str)); $st ...

  6. 使用jQuery解析JSON数据

    我们先以解析上例中的comments对象的JSON数据为例,然后再小结jQuery中解析JSON数据的方法. 上例中得到的JSON数据如下,是一个嵌套JSON: {"comments&quo ...

  7. HTTP 和FTP 状态信息总结(留着自己用)

    HTTP 状态信息 HTTP 400 – 请求无效HTTP 401.1 – 未授权:登录失败HTTP 401.2 – 未授权:服务器配置问题导致登录失败HTTP 401.3 – ACL 禁止访问资源H ...

  8. IOS监听屏幕状态

    一.定义两个宏   //锁屏通知 #define NotificationOff CFSTR("com.apple.springboard.lockcomplete")   //解 ...

  9. HTML 5 应用程序缓存(上)

    什么是应用程序缓存(Application Cache)?HTML5 引入了应用程序缓存,这意味着 web 应用可进行缓存,并可在没有因特网连接时进行访问. 应用程序缓存为应用带来三个优势: 离线浏览 ...

  10. async和await

    总结下博客园中看到的async和await public static class TaskAsyncHelper { /// <summary> /// 将一个方法function异步运 ...