门户:Codeforces Round #277 (Div. 2)

486A. Calculating Function

裸公式= =

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ; typedef long long LL ; LL n ; int main () {
while ( ~scanf ( "%I64d" , &n ) ) printf ( "%I64d\n" , n / 2 - ( n % 2 ? n : 0 ) ) ;
return 0 ;
}

486B. OR in Matrix

依据题意,将a矩阵必须为0的地方先填充为0,其它地方置为1,然后对b矩阵中为1的bij推断第i行或第j列是否有1,没有输出NO,推断到最后假设全部的bij都是合法的,则输出YES。

#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std ; typedef long long LL ; #define rep( i , a , b ) for ( int i = ( a ) ; i < ( b ) ; ++ i )
#define For( i , a , b ) for ( int i = ( a ) ; i <= ( b ) ; ++ i )
#define rev( i , a , b ) for ( int i = ( a ) ; i >= ( b ) ; -- i )
#define clr( a , x ) memset ( a , x , sizeof a )
#define mid ( ( l + r ) >> 1 ) int a[105][105] ;
int b[105][105] ;
int R[105] , C[105] ;
int n , m ; void solve () {
clr ( R , 0 ) ;
clr ( C , 0 ) ;
For ( i , 1 , n ) For ( j , 1 , m ) a[i][j] = 1 ;
For ( i , 1 , n ) For ( j , 1 , m ) {
scanf ( "%d" , &b[i][j] ) ;
if ( !b[i][j] ) {
For ( k , 1 , m ) a[i][k] = 0 ;
For ( k , 1 , n ) a[k][j] = 0 ;
}
}
For ( i , 1 , n ) For ( j , 1 , m ) {
R[i] += a[i][j] ;
C[j] += a[i][j] ;
}
For ( i , 1 , n ) For ( j , 1 , m ) if ( b[i][j] ) {
if ( a[i][j] ) continue ;
if ( R[i] || C[j] ) continue ;
printf ( "NO\n" ) ;
return ;
}
printf ( "YES\n" ) ;
For ( i , 1 , n ) For ( j , 1 , m ) printf ( "%d%c" , a[i][j] , j < m ? ' ' : '\n' ) ;
} int main () {
while ( ~scanf ( "%d%d" , &n , &m ) ) solve () ;
return 0 ;
}

486C. Palindrome Transformation

贪心,其实仅仅用在初始位置所在的字符串半边处理便足够了,于是考虑几种情况,判一下就可以。这题错的吐血了。少打两个else,导致绝杀失败,不然30多名好歹好看一点。

#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std ; typedef long long LL ; #define rep( i , a , b ) for ( int i = ( a ) ; i < ( b ) ; ++ i )
#define For( i , a , b ) for ( int i = ( a ) ; i <= ( b ) ; ++ i )
#define rev( i , a , b ) for ( int i = ( a ) ; i >= ( b ) ; -- i )
#define clr( a , x ) memset ( a , x , sizeof a )
#define mid ( ( l + r ) >> 1 ) const int MAXN = 100005 ; char s[MAXN] ;
int a[MAXN] ;
int n , p ; void solve () {
int ans = 0 ;
clr ( a , 0 ) ;
scanf ( "%s" , s + 1 ) ;
int l = n + 1 , r = 1 ;
For ( i , 1 , n / 2 ) {
if ( s[i] != s[n - i + 1] ) {
a[i] = abs ( s[i] - s[n - i + 1] ) ;
a[n - i + 1] = a[i] = min ( a[i] , 26 - a[i] ) ;
ans += a[i] ;
}
}
if ( p <= n / 2 ) {
For ( i , 1 , n / 2 ) if ( a[i] ) l = min ( l , i ) , r = max ( r , i ) ;
} else {
For ( i , n / 2 + 1 , n ) if ( a[i] ) l = min ( l , i ) , r = max ( r , i ) ;
}
if ( l != n + 1 ) {
if ( p <= l ) ans += r - p ;
else if ( p >= r ) ans += p - l ;
else ans += min ( r - l + r - p , r - l + p - l ) ;
}
printf ( "%d\n" , ans ) ;
} int main () {
while ( ~scanf ( "%d%d" , &n , &p ) ) solve () ;
return 0 ;
}

486D. Valid Sets

考虑以每一个点作为根结点扩展出一棵树,这个树满足树上全部的节点的权值都不比树根大且val[root]-val[v]<=d。然后能够树型DP求以这个点为树根的集合数。考虑到假设以u为根时扩展的树中包括了与u权值同样的v,那么以v为根时便不能包括u了,这个我们能够用一个数组判重。

详细见代码。

#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std ; typedef long long LL ; #define rep( i , a , b ) for ( int i = ( a ) ; i < ( b ) ; ++ i )
#define For( i , a , b ) for ( int i = ( a ) ; i <= ( b ) ; ++ i )
#define rev( i , a , b ) for ( int i = ( a ) ; i >= ( b ) ; -- i )
#define clr( a , x ) memset ( a , x , sizeof a )
#define mid ( ( l + r ) >> 1 ) const int MAXN = 2005 ;
const int MAXE = 4005 ;
const int mod = 1e9 + 7 ; struct Edge {
int v , n ;
Edge () {}
Edge ( int v , int n ) : v ( v ) , n ( n ) {}
} ; Edge E[MAXE] ;
int H[MAXN] , cntE ;
int val[MAXN] ;
int vis[MAXN][MAXN] ;
LL dp[MAXN] ;
int d , n ;
int root ; void clear () {
cntE = 0 ;
clr ( H , -1 ) ;
clr ( vis , 0 ) ;
} void addedge ( int u , int v ) {
E[cntE] = Edge ( v , H[u] ) ;
H[u] = cntE ++ ;
} LL dfs ( int u , int fa ) {
dp[u] = 1 ;
LL ans = 1 ;
for ( int i = H[u] ; ~i ; i = E[i].n ) {
int v = E[i].v ;
if ( v == fa ) continue ;
if ( val[v] > val[root] || vis[root][v] || val[root] - val[v] > d ) continue ;
if ( val[root] == val[v] ) vis[root][v] = vis[v][root] = 1 ;
LL tmp = dfs ( v , u ) ;
ans = ( ans + tmp * dp[u] % mod ) % mod ;
dp[u] = ( dp[u] + tmp * dp[u] ) % mod ;
}
return ans ;
} void solve () {
int u , v ;
clear () ;
For ( i , 1 , n ) scanf ( "%d" , &val[i] ) ;
rep ( i , 1 , n ) {
scanf ( "%d%d" , &u , &v ) ;
addedge ( u , v ) ;
addedge ( v , u ) ;
}
LL ans = 0 ;
For ( i , 1 , n ) {
root = i ;
ans = ( ans + dfs ( i , 0 ) ) % mod ;
}
printf ( "%I64d\n" , ans ) ;
} int main () {
while ( ~scanf ( "%d%d" , &d , &n ) ) solve () ;
return 0 ;
}

486E. LIS of Sequence

设F1[i]为1~i内以i结尾的LIS。F2[i]为i~n内以i开头的LIS。ans为1~n内的LIS。

1.F1[i]+F2[i]-1<ans。

2.F1[i]+F2[i]-1==ans时长度F1[i]不唯一。

3.F1[i]+F2[i]-1==ans时长度F1[i]唯一。

可用二分求F1[i],F2[i]。

#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std ; typedef long long LL ; #define rep( i , a , b ) for ( int i = ( a ) ; i < ( b ) ; ++ i )
#define For( i , a , b ) for ( int i = ( a ) ; i <= ( b ) ; ++ i )
#define rev( i , a , b ) for ( int i = ( a ) ; i >= ( b ) ; -- i )
#define clr( a , x ) memset ( a , x , sizeof a )
#define mid ( ( l + r ) >> 1 ) const int MAXN = 100005 ; int vis[MAXN] ;
int S[MAXN] , top ;
int a[MAXN] ;
int F1[MAXN] ;
int F2[MAXN] ;
int n ; int search1 ( int x , int l , int r ) {
while ( l < r ) {
int m = mid ;
if ( S[m] >= x ) r = m ;
else l = m + 1 ;
}
return l ;
} int search2 ( int x , int l , int r ) {
while ( l < r ) {
int m = mid ;
if ( S[m] <= x ) r = m ;
else l = m + 1 ;
}
return l ;
} void solve () {
clr ( vis , 0 ) ;
For ( i , 1 , n ) scanf ( "%d" , &a[i] ) ;
top = 0 ;
For ( i , 1 , n ) {
if ( !top || a[i] > S[top] ) {
S[++ top] = a[i] ;
F1[i] = top ;
} else {
int x = search1 ( a[i] , 1 , top ) ;
S[x] = a[i] ;
F1[i] = x ;
}
}
top = 0 ;
rev ( i , n , 1 ) {
if ( !top || a[i] < S[top] ) {
S[++ top] = a[i] ;
F2[i] = top ;
} else {
int x = search2 ( a[i] , 1 , top ) ;
S[x] = a[i] ;
F2[i] = x ;
}
}
int ans = top ;
For ( i , 1 , n ) if ( F1[i] + F2[i] - 1 == ans ) ++ vis[F1[i]] ;
For ( i , 1 , n ) {
if ( F1[i] + F2[i] - 1 < ans ) putchar ( '1' ) ;
else if ( vis[F1[i]] == 1 ) putchar ( '3' ) ;
else putchar ( '2' ) ;
}
printf ( "\n" ) ;
} int main () {
while ( ~scanf ( "%d" , &n ) ) solve () ;
return 0 ;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

【codeforces】Codeforces Round #277 (Div. 2) 解读的更多相关文章

  1. Codeforces Round #277 (Div. 2) 题解

    Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...

  2. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...

  3. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  4. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  5. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  6. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  9. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

随机推荐

  1. iis windows phpstudy安装redis扩展

    说明,我的服务器是2008 64位 php5.4.33 首先下载符合条件的redis扩展,是否符合条件可以参考https://pecl.php.net/package/redis,进入之后,点击&qu ...

  2. (九)RabbitMQ消息队列-通过Headers模式分发消息

    原文:(九)RabbitMQ消息队列-通过Headers模式分发消息 Headers类型的exchange使用的比较少,以至于官方文档貌似都没提到,它是忽略routingKey的一种路由方式.是使用H ...

  3. CCPC2016长春站打铁记

    Day0 晚上到的长春.很冷.到了宾馆.放了行李.然后就去吃了点火锅.很好吃.在福建吃的都没有酱.但是回去后有点拉肚子..几个队友也有同样的反应.路过了吉大.拍了一张照片.哎.压力好大. Day1 来 ...

  4. IT忍者神龟之Hibernat持久化对象-数据表映射配置回想

    1.持久化对象POJO编写规则: 1) 有空參public构造器: 2) 提供标识属性.映射数据表主键: 3) 属性提供setter和getter方法. 4) 属性使用基本数据类型的包装类型.基本类型 ...

  5. 在Eclipse上打包并使用Proguard工具混淆jar包

    近期由于工作须要,学习到了Android jar包的打包与混淆. 之前觉得还是非常easy的,可是自己深入研究下,发现还是有一些东西须要注意的,并且自己也踩了一些坑,在这里写下供同僚们借鉴借鉴. 转载 ...

  6. 【27.22%】【poj2991】Crane

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5772   Accepted: 1571   Special Judge D ...

  7. [NPM] Pass arguments to npm scripts

    Often times you’ll have variations that you’ll want to make to your npm scripts and repeating yourse ...

  8. ubuntu14.04下unix网络编程 环境的配置

    在ubuntu下 首先:在unpv13e文件加下 ./configure cd lib make cd ../libfree make cd ../liggai make cd .. vim lib/ ...

  9. SignalR+AForge实现视频会话[WPF]

    原文:SignalR+AForge实现视频会话[WPF] 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/lordwish/article/detai ...

  10. HDU 1816, POJ 2723 Get Luffy Out(2-sat)

    HDU 1816, POJ 2723 Get Luffy Out pid=1816" target="_blank" style="">题目链接 ...