在div 188中,幸运的达成了这学期的一个目标:CF1800+,所以这次可以打星去做div2,有点爽。

A.Flipping Game 直接枚举

B. Hungry Sequence 由于素数的分布大概10个中有一个,所以直接筛法筛1e5个即可。

C. Magic Five 删除串s中的某些字符,使得他整除5,并且跟删除顺序有关,现在问有k个串s连在一起组成一个新的串,问新的串有多少种删除方式。

我们可以先看每一个串,由于整除5的数的末尾只能为0或者5。

用样例二 13990作为说明。

考虑只有一个时,在13990中,只有第4位(从0开始算),则前面有2^4中删除方式。

如果加上一个,即1399013990时,则删除方式有2^4+2^(4+5)。

如果再加上一个时,即139901399013990,则删除方式有2^4+2^(4+5*2)+2^(4+5*3)。

因此我们可以知道,如果单一一个串S中第i位(从0开始)为0或者5时,该串重复k次,则有

2^i+2^(i+|S|)+...+2^( i+|S|*(len-1) ) = 2^i * ( 2^0+2^len+2^(len*2)+...+2^(len*(n-1)) )

由于n,len都比较大,所以需要用到等比数列求和公式以及快速幂,可以化为

2^i * ( 2^(len*n)-1 ) / 2^len

因此这里的除法需要用到逆元。

于是这题可以解决。

D. Block Tower 只要在同一个连通块中,就可以从一个出发,把其他的所有城市人数上限置为200。

直接DFS一下,进去的时候,该地建100的城市,在DFS在该地结束时,如果该地是由其他城市来到,则直接拆掉该地,然后再把该地置为200。

E.待补。

代码:

A

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll;
typedef unsigned long long ull; #define debug puts("here")
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define foreach(i,vec) for(unsigned i=0;i<vec.size();i++)
#define pb push_back
#define RD(n) scanf("%d",&n)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RD4(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)
#define All(vec) vec.begin(),vec.end()
#define MP make_pair
#define PII pair<int,int>
#define PQ priority_queue /******** program ********************/ const int MAXN = 105; int a[MAXN];
int n; int cc(int x,int y){
int ans = 0;
for(int i=1;i<x;i++)
ans += a[i];
for(int i=x;i<=y;i++)
ans += !a[i];
for(int i=y+1;i<=n;i++)
ans += a[i];
return ans;
} int main(){ #ifndef ONLINE_JUDGE
freopen("sum.in","r",stdin);
//freopen("sum.out","w",stdout);
#endif while(cin>>n){
int ans = 0;
rep1(i,n)
RD(a[i]);
rep1(i,n)
for(int j=i;j<=n;j++)
ans = max(ans,cc(i,j));
cout<<ans<<endl;
} return 0;
}

B

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll;
typedef unsigned long long ull; #define debug puts("here")
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define foreach(i,vec) for(unsigned i=0;i<vec.size();i++)
#define pb push_back
#define RD(n) scanf("%d",&n)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RD4(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)
#define All(vec) vec.begin(),vec.end()
#define MP make_pair
#define PII pair<int,int>
#define PQ priority_queue /******** program ********************/ const int MAXN = 2e6+5; vector<int> p;
bool use[MAXN]; void init(){
for(int i=2;i<MAXN;i++)
if(!use[i]){
p.pb(i);
for(int j=i+i;j<MAXN;j+=i)
use[j] = true;
}
} int main(){ #ifndef ONLINE_JUDGE
freopen("sum.in","r",stdin);
//freopen("sum.out","w",stdout);
#endif init();
int n;
while(cin>>n){
rep(i,n)
printf("%d ",p[i]);
puts("");
} return 0;
}

  

C

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll;
typedef unsigned long long ull; #define debug puts("here")
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define foreach(i,vec) for(unsigned i=0;i<vec.size();i++)
#define pb push_back
#define RD(n) scanf("%d",&n)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RD4(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)
#define All(vec) vec.begin(),vec.end()
#define MP make_pair
#define PII pair<int,int>
#define PQ priority_queue /******** program ********************/ const ll MOD = 1000000007; ll pw(ll p, ll n){
ll sum = 1;
while(n > 0){
if(n & 1)
sum = (sum * p) % MOD;
n >>= 1;
p = p * p % MOD;
}
return sum;
} void ex_gcd(ll a,ll b,ll &gcd,ll &x,ll &y){
if(b==0){
x = 1;
y = 0;
gcd = a;
}else{
ex_gcd(b,a%b,gcd,y,x);
y -= x*(a/b);
}
} ll Inv(ll n){
ll x,y,gcd;
ex_gcd(n,MOD,gcd,x,y);
return gcd==1 ? (x%MOD+MOD)%MOD : -1;
} int main(){ #ifndef ONLINE_JUDGE
freopen("sum.in","r",stdin);
//freopen("sum.out","w",stdout);
#endif string s;
ll n;
while(cin>>s>>n){
ll len = s.size();
ll ans = 0; rep(i,len)
if(s[i]=='0'||s[i]=='5')
ans += pw(2,i)*Inv( pw(2,len)-1 )%MOD*( pw(2,len*n)-1 )%MOD; cout<<(ans%MOD+MOD)%MOD<<endl;
} return 0;
}

  

D

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll;
typedef unsigned long long ull; #define debug puts("here")
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define foreach(i,vec) for(unsigned i=0;i<vec.size();i++)
#define pb push_back
#define RD(n) scanf("%d",&n)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RD4(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)
#define All(vec) vec.begin(),vec.end()
#define MP make_pair
#define PII pair<int,int>
#define PQ priority_queue /******** program ********************/ const int MAXN = 505; char s[MAXN][MAXN];
int n,m;
bool use[MAXN][MAXN]; struct node{
char op;
int x,y;
node(){}
node(char a,int b,int c):op(a),x(b),y(c){}
}; vector<node> vec; int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0}; bool out(int x,int y){
return x<1||y<1||x>n||y>m;
} void dfs(int x,int y,bool has){
use[x][y] = true; bool ok = false;
rep(i,4){
int cx = dx[i]+x;
int cy = dy[i]+y;
if(!out(cx,cy)&&!use[cx][cy]&&s[cx][cy]=='.')
ok = true;
} if(!ok&&has){
vec.pb( node('R',x,y) );
return;
} vec.pb( node('B',x,y) );
rep(i,4){
int cx = dx[i]+x;
int cy = dy[i]+y;
if( !out(cx,cy) && !use[cx][cy] && s[cx][cy]=='.'){
dfs(cx,cy,true);
ok = true;
}
} if(has){
vec.pb( node('D',x,y) );
vec.pb( node('R',x,y) );
}
} int main(){ #ifndef ONLINE_JUDGE
freopen("sum.in","r",stdin);
//freopen("sum.out","w",stdout);
#endif int ncase = false;
while(cin>>n>>m){
vec.clear();
ncase?puts(""):ncase = true;
memset(use,false,sizeof(use));
rep1(i,n)
scanf("%s",s[i]+1); rep1(i,n)
rep1(j,m)
if(s[i][j]=='.' && !use[i][j])
dfs(i,j,false);
cout<<vec.size()<<endl;
foreach(i,vec)
printf("%c %d %d\n",vec[i].op,vec[i].x,vec[i].y);
} return 0;
}

  

Codeforces Round #191 (Div. 2)的更多相关文章

  1. 贪心 Codeforces Round #191 (Div. 2) A. Flipping Game

    题目传送门 /* 贪心:暴力贪心水水 */ #include <cstdio> #include <algorithm> #include <cstring> us ...

  2. codeforces水题100道 第二十题 Codeforces Round #191 (Div. 2) A. Flipping Game (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/327/A题意:你现在有n张牌,这些派一面是0,另一面是1.编号从1到n,你需要翻转[i,j]区间的 ...

  3. Codeforces Round #191 (Div. 2) E题

    状态压缩DP,算sum,本来是枚举的,结果TLE了.. #include <iostream> #include <cstring> #include <cstdio&g ...

  4. Codeforces Round #191 (Div. 2) D. Block Tower

    D. Block Tower time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  5. Codeforces Round #191 (Div. 2)---A. Flipping Game

    Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. Codeforces Round #191 (Div. 2) B. Hungry Sequence(素数筛选法)

    . Hungry Sequence time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. Codeforces Round #191 (Div. 2) A. Flipping Game(简单)

    A. Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  8. Codeforces Round #191 (Div. 2) A. Flipping Game【*枚举/DP/每次操作可将区间[i,j](1=<i<=j<=n)内牌的状态翻转(即0变1,1变0),求一次翻转操作后,1的个数尽量多】

    A. Flipping Game     time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. (转)在iOS中使用icon font

    http://ued.taobao.org/blog/?p=8579 在开发阿里数据iOS版客户端的时候,由于项目进度很紧,项目里的所有图标都是用最平常的背景图片方案来实现.而为了要兼容普通屏与Ret ...

  2. Linux下c/c++项目代码覆盖率的产生方法

    最近做了一系列的单元测试相关的工作,除了各种规范及测试框架以外,讨论比较多的就是关于代码覆盖率的产生,c/c++与其他的一些高级语言或者脚本语言相比较而言,例如 Java..Net和php/pytho ...

  3. Nginx应用案例分享:压力测试

    在运维工作中,压力测试是一项非常重要的工作.比如在一个网站上线之前,能承受多大访问量.在大访问量情况下性能怎样,这些数据指标好坏将会直接影响用户体验. 但是,在压力测试中存在一个共性,那就是压力测试的 ...

  4. #pragma comment使用

    编程经常碰到,理解的总不是很透彻,在这里查阅资料总结一下! 在编写程序的时候,我们常用到#pragma指令来设定编译器的状态或者是指示编译器完成一些特定的动作. #pragma once : 这是一个 ...

  5. 贪心-poj-2437-Muddy roads

    题目链接: http://poj.org/problem?id=2437 题目意思: 给n个区间,每次可以用长度为L的棒A去覆盖,求将所有区间覆盖至少需要几次.给的区间不覆盖. 解题思路: 简单贪心. ...

  6. Hql处理日期格式化问题

    1. Date date=Calendar.getInstance().getTime(); Date date1=Calendar.getInstance().getTime(); String h ...

  7. CentOS 6.5部署HTTP WEB服务器和FTP服务器

    转载自:http://www.server110.com/linux/201403/8613.html [题记]本文使用CentOS 6.5 minimal快速搭建HTTP服务器和仅供授权用户登陆的F ...

  8. windows服务控制类

    /// <summary> /// 服务调用控制 /// </summary> public class WinServiceController { /// <summ ...

  9. PC/UVa 题号: 110101/100 The 3n+1 problem (3n+1 问题)

     The 3n + 1 problem  Background Problems in Computer Science are often classified as belonging to a ...

  10. Struts2内建校验器(基于校验框架的文件校验)

    位于xwork-2.0.4.jar压缩包中( com.opensymphony.xwork2.validator.validators)有个文件default.xml ,该文件中定义了Struts2框 ...