CF 191 div2
A.数据量很小,直接爆搞。
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <string>
- #include <cmath>
- #include <cstring>
- #include <queue>
- #include <set>
- #include <vector>
- #include <stack>
- #include <map>
- #include <iomanip>
- #define PI acos(-1.0)
- #define Max 2505
- #define inf 1<<28
- #define LL(x) ( x << 1 )
- #define RR(x) ( x << 1 | 1 )
- #define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i )
- #define ll long long
- #define mem(a,b) memset(a,b,sizeof(a))
- #define mp(a,b) make_pair(a,b)
- #define PII pair<int,int>
- using namespace std;
- int a[111] ;
- int num[11111] ;
- int main() {
- int n ;
- cin >> n ;
- int ans = 0 ;
- for (int i = 1 ; i <= n ;i ++ ){
- cin >> a[i] ;
- num[i] = num[i - 1] + a[i] ;
- }
- ans = num[n] - 1 ;
- for(int i = 1; i <= n; ++i ){
- for(int j = 1; j <= i; ++ j){
- int sum = num[n] - 2 * ( num[i] - num[j-1] ) + ( i - j + 1 );
- ans = max(sum ,ans) ;
- }
- }
- cout << ans << endl;
- return 0 ;
- }
B,直接打个素数表,然后输出前N个素数就可以了。
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <string>
- #include <cmath>
- #include <cstring>
- #include <queue>
- #include <set>
- #include <vector>
- #include <stack>
- #include <map>
- #include <iomanip>
- #define PI acos(-1.0)
- #define Max 2505
- #define inf 1<<28
- #define LL(x) ( x << 1 )
- #define RR(x) ( x << 1 | 1 )
- #define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i )
- #define ll long long
- #define mem(a,b) memset(a,b,sizeof(a))
- #define mp(a,b) make_pair(a,b)
- #define PII pair<int,int>
- using namespace std;
- bool flag[11111111] ;
- void prime(){
- flag[0] = 1 ;
- flag[1] = 1 ;
- flag[2] = 0 ;
- for (int i = 2 ;i <= 1300000 ; i ++ ){
- if(!flag[i]){
- for (int j = 2 * i ;j <= 1300000 ;j += i){
- flag[j] = 1 ;
- }
- }
- }
- }
- int a[111] ;
- int num[1111111] ;
- int main() {
- prime() ;
- int nn = 0 ;
- for (int i = 2 ;i <= 1300000 ;i ++ ){
- if(!flag[i])num[nn ++ ] = i ;
- }
- int n ;
- cin >> n ;
- cout << num[0] ;
- for (int i = 1 ;i < n ;i ++ ){
- printf(" %d",num[i]) ;
- }
- cout << endl;
- return 0 ;
- }
C,可以推出,k个连续的字符串是满足等比数列的关系的。
所以我们只需求出a1 和比例q就可以了。
首相就是只有一个字符串的时候,所有的删除的总和。
q就是pow(2 , l),l是字符串的长度。
等比数列求和公式 (a1 * (q ^ n - 1)) / (q - 1)%MOD 。先将a1 拿到外面去,不参与计算。我们设q ^ n - 1为a ,q - 1 为b 。那么式子就变成a / b %MOD 。这就变成很熟悉的拓展欧几里德了,先求出b % MOD的逆元x . x * b % MOD = 1 ,那么 (a / b ) %MOD * (x * b) % MOD 的值不变,那么可以将式子化简成(a * x) % MOD 。
最后再将a1乘上即可。
- #define MOD 1000000007
- char a[111111] ;
- inline ll extend_gcd(ll a ,ll b , ll& x , ll& y){
- ll ans , t ;
- if(b == 0){
- x = 1 ;
- y = 0 ;
- return a ;
- }
- ans = extend_gcd(b , a % b ,x ,y ) ;
- t = x ;
- x = y ;
- y = t - (a / b) * y ;
- return ans ;
- }
- ll quick_pow(ll a ,ll b , ll M){
- ll ret = 1 ;
- ll temp = a ;
- while(b){
- if(b & 1){
- ret = (ret * temp) % M ;
- }
- temp = (temp * temp) % M ;
- b >>= 1 ;
- }
- return ret ;
- }
- int main(){
- cin >> a ;
- int k ;
- cin >> k ;
- int l = strlen(a) ;
- ll a1 = 0 ;
- REP(i , 0 ,l - 1 ){
- if(a[i] == '0' || a[i] == '5'){
- a1 = (a1 + quick_pow(2 ,i ,MOD)) % MOD ;
- }
- }
- ll a = quick_pow(2 , l ,MOD) ;
- ll aa = (a - 1 + MOD) % MOD ;
- ll x , y ;
- extend_gcd(aa ,MOD , x ,y) ;
- x = (x + MOD) % MOD ;
- ll c = (quick_pow(a , k ,MOD) - 1) * x % MOD ;
- ll ans = c * a1 % MOD ;
- cout << ans << endl;
- return 0 ;
- }
D,DFS,每次进入一个空地,先将他建成蓝色的,然后向四个方向DFS,最后回溯的时候将这个蓝色的建筑拆掉建成红色的,当然第一个进入的点是不能建成红色的。
这个很容易证明,一个联通块里面,肯定有一个是蓝色的,其他都是红色的。
- int n , m ;
- char op[11111111] ;
- int xx[11111111] ;
- int yy[11111111] ;
- int ss[555][555] ;
- char Map[555][555] ;
- int num = 0 ;
- void dfs(int x ,int y ,int first ) {
- if(x < 1 || x > n || y < 1 || y > m)return ;
- op[num] = 'B' ;
- xx[num] = x ;
- yy[num] = y ;
- num ++ ;
- ss[x][y] = 0 ;
- if(ss[x - 1][y])dfs(x - 1 ,y , 1) ;
- if(ss[x][y - 1])dfs(x ,y - 1 ,1 ) ;
- if(ss[x + 1][y])dfs(x + 1 ,y , 1) ;
- if(ss[x][y + 1])dfs(x ,y + 1 ,1 ) ;
- if(first) {
- op[num] = 'D' ;
- xx[num] = x ;
- yy[num] = y ;
- num ++ ;
- op[num] = 'R' ;
- xx[num] = x ;
- yy[num] = y ;
- num ++ ;
- }
- }
- int main() {
- cin >> n >> m ;
- for (int i = 1 ; i <= n ; i ++ ) {
- for (int j = 1 ; j <= m ; j ++ ) {
- cin >> Map[i][j] ;
- if(Map[i][j] == '.') {
- ss[i][j] = 1 ;
- }
- }
- }
- for (int i = 1 ; i <= n ; i ++ ) {
- for (int j = 1 ; j <= m ; j ++ ) {
- if(ss[i][j]) {
- dfs(i ,j , 0 ) ;
- }
- }
- }
- cout << num << endl;
- for (int i = 0 ; i < num ; i ++ ) {
- cout << op[i] << " " << xx[i] << " " << yy[i] << endl;
- }
- return 0 ;
- }
E。状态压缩DP。
枚举1<< 24的状态。
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <string>
- #include <cmath>
- #include <cstring>
- #include <queue>
- #include <set>
- #include <vector>
- #include <stack>
- #include <map>
- #include <iomanip>
- #define PI acos(-1.0)
- #define Max 2505
- #define inf 1<<28
- #define LL(x) ( x << 1 )
- #define RR(x) ( x << 1 | 1 )
- #define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i )
- #define ll long long
- #define mem(a,b) memset(a,b,sizeof(a))
- #define mp(a,b) make_pair(a,b)
- #define PII pair<int,int>
- using namespace std;
- #define MOD 1000000007
- inline void RD(int &ret) {
- char c;
- do {
- c = getchar();
- } while(c < '0' || c > '9') ;
- ret = c - '0';
- while((c=getchar()) >= '0' && c <= '9')
- ret = ret * 10 + ( c - '0' );
- }
- int a[111111] ;
- int sum[1 << 24] ;
- int dp[1 << 24] ;
- int k[11] ;
- int main(){
- int n ;
- cin >> n ;
- for (int i = 0 ;i < n ; i ++ ){
- RD(a[i]) ;
- }
- int m ;
- cin >> m ;
- for (int i = 0 ;i < m ;i ++ ){
- RD(k[i]) ;
- }
- dp[0] = 1 ;
- for (int i = 1 ;i < (1 << n) ; ++ i){//枚举当前路径
- int pos ;
- bool flag = 0 ;
- sum[i] = 0 ;
- for (int j = 0 ;j < n ;j ++ ){
- if(i & (1 << j)){//i 在 j 这点为1 ,直接在这里找出sum[i]的值会T。O(2 ^ 24 * n)
- pos = j ;//一开始我直接写sum[i] += a[j] ;就T了
- break ;
- }
- }
- sum[i] = sum[i ^ (1 << pos)] + a[pos] ;//i 状态的所有步数。
- for (int j = 0 ; j < m ;j ++ ){//i状态的步数是否不能走。
- if(sum[i] == k[j]){
- dp[i] = 0 ;
- flag = 1 ;
- break ;
- }
- }
- if(flag)continue ;
- dp[i] = 0 ;
- for (int j = 0 ;j < n ;j ++ ){
- if(i & (1 << j)){//i 这位可以由i ^ (1 << j )这一状态过来。
- dp[i] = (dp[i] + dp[i ^ (1 << j)]) ;
- if(dp[i] >= MOD)dp[i] -= MOD ;
- }
- }
- }
- cout << dp[(1 << n) - 1] << endl;
- return 0 ;
- }
CF 191 div2的更多相关文章
- cf 442 div2 F. Ann and Books(莫队算法)
cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i, ...
- CF#603 Div2
差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一 ...
- CF R631 div2 1330 E Drazil Likes Heap
LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了 ...
- CF#581 (div2)题解
CF#581 题解 A BowWow and the Timetable 如果不是4幂次方直接看位数除以二向上取整,否则再减一 #include<iostream> #include< ...
- [CF#286 Div2 D]Mr. Kitayuta's Technology(结论题)
题目:http://codeforces.com/contest/505/problem/D 题目大意:就是给你一个n个点的图,然后你要在图中加入尽量少的有向边,满足所有要求(x,y),即从x可以走到 ...
- CF 191 总结
A. Flipping Game 链接:http://codeforces.com/contest/327/problem/A 题意:从 i 到 j 翻转一次使得 1 的 个数最多~ 直接暴力搞~ # ...
- CF 197 DIV2 Xenia and Bit Operations 线段树
线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i ...
- CF#345 div2 A\B\C题
A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...
- CF R303 div2 C. Woodcutters
C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- 《Effective C++》Item2:尽量以const,enum,inline替换#define
1. 宏定义 #define ASPECT_RATIO 1.653 该宏定义ASPECT_RATIO也许从来没有被编译器看到,也许在编译器开始处理源码之前就已经被预处理器替换了.所以记号名称ASPEC ...
- nginx install
./configure --prefix=/home/allen.mh/local/nginx --with-http_ssl_module --with-http_sub_module --with ...
- Cocos2dx游戏开发系列笔记13:一个横版拳击游戏Demo完结篇
懒骨头(http://blog.csdn.net/iamlazybone QQ:124774397 ) 写下这些东西的同时 旁边放了两部电影 周星驰的<还魂夜> 甄子丹的<特殊身份& ...
- Html 小插件6 百度新闻插件
新闻免费代码"http://news.baidu.com/newscode.html ,便可在输入希望订阅的关键词后,根据相关选项的设置,百度便非常快的在当前页面的文本编辑框内生成相关代码. ...
- rsyslogd: error during parsing file /etc/rsyslog.conf, on or before line 55: warnings occured in fil
zjtest7-frontend:/root# rsyslogd -n rsyslogd: error during parsing file /etc/rsyslog.conf, on or bef ...
- HDU 5768 Lucky7(CRT+容斥原理)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5768 [题目大意] 求出一个区间内7的倍数中,对于每个ai取模不等于bi的数的个数. [题解] 首 ...
- CodeForces 235C Cyclical Quest(后缀自动机)
[题目链接] http://codeforces.com/contest/235/problem/C [题目大意] 给出一个字符串,给出一些子串,问每个子串分别在母串中圆环匹配的次数,圆环匹配的意思是 ...
- POJ 3294 Life Forms(后缀数组+二分答案)
[题目链接] http://poj.org/problem?id=3294 [题目大意] 求出在至少在一半字符串中出现的最长子串. 如果有多个符合的答案,请按照字典序输出. [题解] 将所有的字符串通 ...
- 具体解释http 协议
HTTP协议的主要特点可概括例如以下: 1.支持客户/server模式. 2.简单高速:客户向server请求服务时,仅仅需传送请求方法和路径.请求方法经常使用的有GET.HEAD.POST.每种方法 ...
- POJ 1556 The Doors(计算几何+最短路)
这题就是,处理出没两个点.假设能够到达,就连一条边,推断可不能够到达,利用线段相交去推断就可以.最后求个最短路就可以 代码: #include <cstdio> #include < ...