【codeforces】Codeforces Round #277 (Div. 2) 解读
门户:Codeforces Round #277 (Div. 2)
裸公式= =
#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 ;
}
依据题意,将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 ;
}
考虑以每一个点作为根结点扩展出一棵树,这个树满足树上全部的节点的权值都不比树根大且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 ;
}
设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) 解读的更多相关文章
- Codeforces Round #277 (Div. 2) 题解
Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...
- 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation
题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
随机推荐
- 【2037】利用字符串处理,输出x+y的结果
Time Limit: 1 second Memory Limit: 50 MB [问题描述] 输入两个整数x,y输出它们的和.(0<=x,y<=10的100次幂) [输入] 共2行: ...
- SAP 中的popup dialog (弹出对话框) 常见实现方法
方法1: FM:POPUP_TO_CONFIRM(标准对话弹出消息) 有三个button:YES-NO-CANL,可进行对应的逻辑推断 可设定标题,描写叙述问题,不方便对文本进行换行等排版,不能改 ...
- QAtomicInt支持四种类型的操作,Relaxed、Acquired、Release、Ordered
Memory Ordering Background 很久很久很久以前,CPU忠厚老实,一条一条指令的执行我们给它的程序,规规矩矩的进行计算和内存的存取. 很久很久以前, CPU学会了Out-Of ...
- c# 读/写文件(各种格式)
最简单的: --------写 //content是要写入文本的字符串 //(@txtPath + @"\" + rid + ".txt");要被写入的TXT ...
- 定时清理tomcat日志文件
原文链接:https://blog.csdn.net/qq_37936542/article/details/78788466 需求:最近公司服务器发现磁盘经常会被占满,查其原因是因为大量的日志文件. ...
- [Angular] Export directive functionalities by using 'exportAs'
Directive ables to change component behaives and lookings. Directive can also export some APIs which ...
- Java实现的并发任务处理实例
本文实例讲述了Java实现的并发任务处理方法.分享给大家供大家参考,具体如下: public void init() { super.init(); this.ioThreadPool = new T ...
- ZOJ Monthly, June 2014 解题报告
A.Another Recurrence Sequence problemId=5287">B.Gears 题目大意:有n个齿轮,一開始各自为一组.之后进行m次操作,包含下面4种类型: ...
- 使用多target来构建大量相似App
转自 come from : http://devtang.com/blog/2013/10/17/the-tech-detail-of-ape-client-1/ 猿题库iOS客户端的技术细节(一) ...
- ag-admin部署使用心得
开源地址:https://github.com/wxiaoqi/Spring-Cloud-AG-Admin(后端)https://gitee.com/geek_qi/AG-Admin-v2.0(后端) ...