博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces1165
阅读量:5289 次
发布时间:2019-06-14

本文共 7911 字,大约阅读时间需要 26 分钟。

CodeForces1165A

水题,数一数后\(x\)位里的\(1\),注意\(y+1\)位是不是\(1\)就行了.

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MEM(x,y) memset ( x , y , sizeof ( x ) )#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)#define per(i,a,b) for (int i = (a) ; i >= (b) ; -- i)#define pii pair < int , int >#define X first#define Y second#define rint read
#define int long long#define pb push_backusing std::queue ;using std::set ;using std::pair ;using std::max ;using std::min ;using std::priority_queue ;using std::vector ;using std::swap ;using std::sort ;using std::unique ;using std::greater ;template < class T > inline T read () { T x = 0 , f = 1 ; char ch = getchar () ; while ( ch < '0' || ch > '9' ) { if ( ch == '-' ) f = - 1 ; ch = getchar () ; } while ( ch >= '0' && ch <= '9' ) { x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ; ch = getchar () ; } return f * x ;}const int N = 2e5 + 100 ;int n , x , y , ans ;bool v[N] ; char s[N] ;signed main (int argc , char * argv[]) { n = rint () ; x = rint () ; y = rint () ; scanf ("%s" , s + 1 ) ; rep ( i , 1 , n ) v[i] = s[i] == '1' ; per ( i , n , n - x + 1 ) if ( v[i] ) ++ ans ; if ( ! v[n-y] ) ++ ans ; else -- ans ; printf ("%lld\n" , ans ) ; system ("pause") ; return 0 ;}

CodeForces1165B

水题,把比赛排个序,能打就打.

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MEM(x,y) memset ( x , y , sizeof ( x ) )#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)#define per(i,a,b) for (int i = (a) ; i >= (b) ; -- i)#define pii pair < int , int >#define X first#define Y second#define rint read
#define int long long#define pb push_backusing std::queue ;using std::set ;using std::pair ;using std::max ;using std::min ;using std::priority_queue ;using std::vector ;using std::swap ;using std::sort ;using std::unique ;using std::greater ;template < class T > inline T read () { T x = 0 , f = 1 ; char ch = getchar () ; while ( ch < '0' || ch > '9' ) { if ( ch == '-' ) f = - 1 ; ch = getchar () ; } while ( ch >= '0' && ch <= '9' ) { x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ; ch = getchar () ; } return f * x ;}const int N = 2e6 + 100 ;int n , v[N] , ans ;signed main (int argc , char * argv[]) { n = rint () ; rep ( i , 1 , n ) v[i] = rint () ; sort ( v + 1 , v + n + 1 ) ; int now = 1 , cur = 1 ; while ( true ) { if ( v[cur] >= now ) ++ ans ; else { while ( v[cur] < now && cur <= n ) ++ cur ; if ( cur > n ) break ; ++ ans ; } ++ now ; ++ cur ; } printf ("%lld\n" , ans ) ; system ("pause") ; return 0 ;}

CodeForces1165C

水题,从前向后扫原串,能取就取,最后注意取出来的长度就行了.

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MEM(x,y) memset ( x , y , sizeof ( x ) )#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)#define per(i,a,b) for (int i = (a) ; i >= (b) ; -- i)#define pii pair < int , int >#define X first#define Y second#define rint read
#define int long long#define pb push_backusing std::queue ;using std::set ;using std::pair ;using std::max ;using std::min ;using std::priority_queue ;using std::vector ;using std::swap ;using std::sort ;using std::unique ;using std::greater ;template < class T > inline T read () { T x = 0 , f = 1 ; char ch = getchar () ; while ( ch < '0' || ch > '9' ) { if ( ch == '-' ) f = - 1 ; ch = getchar () ; } while ( ch >= '0' && ch <= '9' ) { x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ; ch = getchar () ; } return f * x ;}const int N = 2e6 + 100 ;int n , ans ;char s[N] , t[N] ;signed main (int argc , char * argv[]) { n = rint () ; scanf ("%s" , s + 1 ) ; if ( ! ( n & 1 ) ) { bool f = true ; for (int i = 1 ; i <= n - 1 ; i += 2) if ( s[i] == s[i+1] ) { f = false ; break ; } if ( f ) { puts ("0") ; rep ( i , 1 , n ) putchar ( s[i] ) ; putchar ( 10 ) ; system ("pause") ; return 0 ; } } int cur = 0 ; rep ( i , 1 , n ) { if ( cur & 1 ) { while ( s[i] == t[cur] && i <= n ) ++ i ; if ( i > n ) { -- cur ; break ; } t[++cur] = s[i] ; } else t[++cur] = s[i] ; } if ( cur & 1 ) -- cur ; printf ("%lld\n" , n - cur ) ; if ( cur ) rep ( i , 1 , cur ) putchar ( t[i] ) ; putchar(10) ; system ("pause") ; return 0 ;}

CodeForces1165D

水题,把给定的因子排个序,取\(d_1\times d_n\)为假定答案,然后从两侧向中间扫,遇到矛盾直接\(-1\).

如果通过了上面的检测,就再\(\Theta(\sqrt{n})\)枚举因子,判断是否全部出现即可.

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MEM(x,y) memset ( x , y , sizeof ( x ) )#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)#define per(i,a,b) for (int i = (a) ; i >= (b) ; -- i)#define pii pair < int , int >#define X first#define Y second#define rint read
#define int long long#define pb push_backusing std::queue ;using std::set ;using std::pair ;using std::max ;using std::min ;using std::priority_queue ;using std::vector ;using std::swap ;using std::sort ;using std::unique ;using std::greater ;template < class T > inline T read () { T x = 0 , f = 1 ; char ch = getchar () ; while ( ch < '0' || ch > '9' ) { if ( ch == '-' ) f = - 1 ; ch = getchar () ; } while ( ch >= '0' && ch <= '9' ) { x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ; ch = getchar () ; } return f * x ;}const int N = 521 ;const int M = 1e7 + 100 ;int n , d[N] , ans ;bool mk[M] ;signed main (int argc , char * argv[]) { int T = rint () ; while ( T -- ) { n = rint () ; MEM ( mk , 0 ) ; rep ( i , 1 , n ) d[i] = rint () , mk[d[i]] = true ; sort ( d + 1 , d + n + 1 ) ; bool f = true ; int cmp = d[1] * d[n] ; int maxf = n >> 1 ; for (int i = 2 ; i <= maxf ; ++ i) if ( d[i] * d[n-i+1] != cmp ) { f = false ; break ; } if ( n & 1 ) if ( d[maxf+1] * d[maxf+1] != cmp ) f = false ; if ( f ) for (int i = 2 ; i * i <= cmp + 1 ; ++ i) if ( cmp % i == 0 && ( ! mk[i] || ! mk[cmp/i] ) ) f = false ; if ( ! f ) puts ("-1") ; else printf ("%lld\n" , cmp ) ; } system ("pause") ; return 0 ;}

CodeForces1165E

有点东西的题目.

考虑每个位置的贡献,你发现每个位置都是独立的,然后分别考虑贡献就行了.
贡献就是经过它的区间个数乘上\(a\)数组,然后把得到的贡献数组和\(b\)反向排序,对应位置统计即可.

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MEM(x,y) memset ( x , y , sizeof ( x ) )#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)#define per(i,a,b) for (int i = (a) ; i >= (b) ; -- i)#define pii pair < int , int >#define X first#define Y second#define rint read
#define int long long#define pb push_backusing std::queue ;using std::set ;using std::pair ;using std::max ;using std::min ;using std::priority_queue ;using std::vector ;using std::swap ;using std::sort ;using std::unique ;using std::greater ;template < class T > inline T read () { T x = 0 , f = 1 ; char ch = getchar () ; while ( ch < '0' || ch > '9' ) { if ( ch == '-' ) f = - 1 ; ch = getchar () ; } while ( ch >= '0' && ch <= '9' ) { x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ; ch = getchar () ; } return f * x ;}const int N = 2e5 + 100 ;const int mod = 998244353 ;int n , a[N] , b[N] , ans , pos[N] ;inline bool cmp (int x , int y) { return x > y ; }signed main (int argc , char * argv[]) { n = rint () ; rep ( i , 1 , n ) a[i] = rint () ; rep ( i , 1 , n ) b[i] = rint () ; rep ( i , 1 , n ) pos[i] = a[i] * ( ( i - 1 ) * ( n - i ) + n ) ; sort ( pos + 1 , pos + n + 1 , cmp ) ; sort ( b + 1 , b + n + 1 ) ; rep ( i , 1 , n ) ans = ( ans + pos[i] % mod * b[i] % mod ) % mod ; printf ("%lld\n" , ans ) ; system ("pause") ; return 0 ;}

转载于:https://www.cnblogs.com/Equinox-Flower/p/11506554.html

你可能感兴趣的文章
【bzoj1163/bzoj1339】[Baltic2008]Mafia 网络流最小割
查看>>
【poj2409】Let it Bead Polya定理
查看>>
11个显著提升 ASP.NET 应用程序性能的技巧——第1部分
查看>>
多线程(二)
查看>>
Java Web技术之JSP与EL表达式
查看>>
剑指Offer:第一个只出现一次的字符
查看>>
今日心得:读书
查看>>
mysql一些简单操作
查看>>
数组常用函数整理
查看>>
如何判断微信内置浏览器 MicroMessenger
查看>>
RN错误随笔 - Unable to resolve module 'AccessibilityInfo'
查看>>
第十三周
查看>>
C# Upload
查看>>
Stripies
查看>>
Red and Black(poj 1979 bfs)
查看>>
记一次百度面试题
查看>>
Java buildTools
查看>>
使用FormData提交表单及上传文件
查看>>
几种经典的网络服务器架构模型的分析与比较
查看>>
struts2.X心得2--第一个struts2案例分析以及整合c3p0连接数据库案例分析
查看>>