在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. CodeForces 689B Mike and Shortcuts (bfs or 最短路)

    Mike and Shortcuts 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/F Description Recently ...

  2. scp命令获取远程文件

    一.scp是什么? scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的,可能会稍微影响 ...

  3. UVaLive 6625 Diagrams & Tableaux (状压DP 或者 DFS暴力)

    题意:给一个的格子图,有 n 行单元格,每行有a[i]个格子,要求往格子中填1~m的数字,要求每个数字大于等于左边的数字,大于上边的数字,问有多少种填充方法. 析:感觉像个DP,但是不会啊...就想暴 ...

  4. CodeForces 589B Layer Cake (暴力)

    题意:给定 n 个矩形是a*b的,问你把每一块都分成一样的,然后全放一块,高度都是1,体积最大是多少. 析:这个题,当时并没有完全读懂题意,而且也不怎么会做,没想到就是一个暴力,先排序,先从大的开始选 ...

  5. oracle ibatis 存储过程 返回游标 嵌套表

    自己解决问题了 问题总结: 1.index by表不能存储在数据库中的type中,故选择嵌套表. 2.ibatis不支持oracle的复合数据类型的返回.(个人理解) 3.替代方案:用返回oracle ...

  6. 为什么 JavaScript 中基本数据类型拥有 toString 之类方法?

    在 JavaSctipt 启示录一书中,关于为什么 JS 中基本数据类型可以调用一堆对象方法.大意即指,当原始数据类型(boolean,Number.String)在调用方法时,JS 将会创建对象,以 ...

  7. iis 启用父目录路径访问

    今天公司有个客户保修网站后台无法访问,我查看了源代码,发现ASP代码本身并没有什么问题.而且我下到本地能够访问.就是在网上不能正常连接,显示入下错误: Server.MapPath() 错误 'ASP ...

  8. asp.net中使用swfupload上传大文件

    转载:http://www.cnblogs.com/niunan/archive/2012/01/12/2320705.html 花了一天多时间研究出来的,其实也就是网上下别人的代码然后再自己修修改改 ...

  9. eclipse中异常的快捷键

    选中你要try的代码,alt+shift+z 就会弹出一个菜单,里面有个try 选项

  10. Sysprep命令详解

    本主题描述了 Windows(R) 8 版本的系统准备 (Sysprep) 工具的命令行语法. 如果你打算创建安装映像以部署到不同的计算机上,则必须运行带有 /generalize 选项的 Syspr ...