http://codeforces.com/contest/489

Problems

 
 
# Name    
A
standard input/output

1 s, 256 MB

   x2668
B
standard input/output

1 s, 256 MB

   x2659
C
standard input/output

1 s, 256 MB

   x2261
D
standard input/output

1 s, 256 MB

   x1151
E
standard input/output

1 s, 256 MB

   x165
F
standard input/output

1 s, 256 MB

   x427

ABCD都是水题,F题有点碉,是个记忆化搜索/DP。

代码:

A:

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define mz(array) memset(array, 0, sizeof(array))
#define mf1(array) memset(array, -1, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("huzhi.txt","w",stdout)
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
typedef long long ll;
typedef unsigned long long ull; const double pi=acos(-1.0);
const double eps=1e-; const int maxn=; int n; int ans;
int a[maxn];
int ax[maxn],ay[maxn]; ll farm(){
int i,j,k;
ll re=;
ans=;
FOR(i,,n-){
k=i;
FOR(j,i+,n-){
if(a[j]<a[k]){
k=j;
}
}
if(k!=i){
ax[ans]=i;
ay[ans]=k;
ans++;
swap(a[k],a[i]);
}
}
return re;
} int main(){
int i;
scanf("%d",&n);
REP(i,n)RD(a[i]);
farm();
WN(ans);
REP(i,ans){
printf("%d %d\n",ax[i],ay[i]);
}
return ;
}

B:

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define mz(array) memset(array, 0, sizeof(array))
#define mf1(array) memset(array, -1, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("huzhi.txt","w",stdout)
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
typedef long long ll;
typedef unsigned long long ull; const double pi=acos(-1.0);
const double eps=1e-; const int maxn=;
const int maxm=; int n,m; //struct Edge{
// int v,next;
//}e[maxm];
//int head[maxn],en;
//
//inline void add(const int &x,const int &y){
// e[en].v=y;
// e[en].next=head[x];
// head[x]=en++;
//} int a[maxn],b[maxn]; int farm(){
sort(a,a+n);
sort(b,b+m);
int i,j;
j=;
int ans=;
REP(i,n){
while(j<m && b[j]<a[i]-)j++;
if(j==m)break;
if(abs(a[i]-b[j])<=){
j++;
ans++;
}
}
return ans;
} int main(){
int i;
RD(n);
REP(i,n)RD(a[i]);
RD(m);
REP(i,m)RD(b[i]);
WN(farm());
return ;
}

C:

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define mz(array) memset(array, 0, sizeof(array))
#define mf1(array) memset(array, -1, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define FORD(i,x,y) for(i=(x);i>=(y);i--)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("huzhi.txt","w",stdout)
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
typedef long long ll;
typedef unsigned long long ull; const double pi=acos(-1.0);
const double eps=1e-; const int maxn=;
const int maxm=; int m,s; //struct Edge{
// int v,next;
//}e[maxm];
//int head[maxn],en;
//
//inline void add(const int &x,const int &y){
// e[en].v=y;
// e[en].next=head[x];
// head[x]=en++;
//} char s1[],s2[]; bool farm(){
if(m> && s==)return ;
if(s > m*)return ;
if(m== && s==){
strcpy(s1,"");
strcpy(s2,"");
return ;
}
int t=s;
s1[]='';
t--;
int i;
FORD(i,m-,){
if(t){
int q=min(,t);
s1[i]=''+q;
t-=q;
}else s1[i]='';
}
if(t)s1[]+=t; t=s;
FOR(i,,m-){
if(t){
int q=min(,t);
s2[i]=''+q;
t-=q;
}else s2[i]='';
}
return ;
} int main(){
RD2(m,s);
if(farm())
printf("%s %s\n",s1,s2);
else puts("-1 -1");
return ;
}

D:

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define mz(array) memset(array, 0, sizeof(array))
#define mf1(array) memset(array, -1, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("huzhi.txt","w",stdout)
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
typedef long long ll;
typedef unsigned long long ull; const double pi=acos(-1.0);
const double eps=1e-; const int maxn=;
const int maxm=; int n,m; struct Edge{
int v,next;
}e[maxm];
int head[maxn],en; inline void add(const int &x,const int &y){
e[en].v=y;
e[en].next=head[x];
head[x]=en++;
} ll ans; int a[maxn][maxn];
int gf; void dfs(int x,int y){
if(y==){
a[gf][x]++;
return;
}
int i;
for(i=head[x]; i!=-; i=e[i].next){
if(e[i].v!=gf)dfs(e[i].v, y-);
}
} void farm(){
int i,j;
ans=;
mz(a);
FOR(i,,n){
gf=i;
dfs(i,);
}
FOR(i,,n){
FOR(j,,n){
if(i!=j){
if(a[i][j]>=){
ans+= a[i][j]*(a[i][j]-)/ ;
}
}
}
}
} int main(){
int i,j;
int x,y;
RD2(n,m);
en=;
mf1(head);
REP(i,m){
RD2(x,y);
add(x,y);
}
farm();
printf("%I64d",ans);
return ;
}

F:

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define mz(array) memset(array, 0, sizeof(array))
#define mf1(array) memset(array, -1, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("huzhi.txt","w",stdout)
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
typedef long long ll;
typedef unsigned long long ull; const double pi=acos(-1.0);
const double eps=1e-; const int maxn=; int n,m,mod; int a[maxn][maxn]; int r[maxn],c[maxn]; ll f[maxn][maxn]; inline ll gank(const int &w1, const int &w0){
//printf("%d,%d\n",w1,w0);
if(f[w1][w0] != -)return f[w1][w0];
ll re=;
if(w0>){
re+=w0*(w0-)/ * gank(w1+,w0-);
re%=mod;
}
if(w0> && w1>){
re+=w0*w1 * gank(w1,w0-);
re%=mod;
}
if(w1>){
re+=w1*(w1-)/ * gank(w1-,w0);
re%=mod;
}
f[w1][w0]=re;
return re;
} ll farm(){
int i,j,k;
// REP(i,n){
// REP(j,n)printf("%d ",a[i][j]);
// puts("");
// }
mz(r);
mz(c);
REP(i,m)REP(j,n){
if(a[i][j]){
r[i]++;
c[j]++;
}
}
REP(i,n){
if(r[i]> || c[i]>)return ;
}
REP(i,m) if(r[i]!=)return ;
int ww[]={};
REP(i,n){
ww[c[i]]++;
}
ll ans=;
mf1(f);
f[][]=;
ans = gank(ww[], ww[]);
return ans;
} int main(){
char c;
int i,j;
RD3(n,m,mod);
mf1(a);
REP(i,m){
REP(j,n){
do{c=getchar();}while(c!='' && c!='');
a[i][j] = c-'';
}
}
printf("%I64d\n",farm());
return ;
}

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

  1. Codeforces Round #277.5 (Div. 2)

    题目链接:http://codeforces.com/contest/489 A:SwapSort In this problem your goal is to sort an array cons ...

  2. Codeforces Round #277.5 (Div. 2) --E. Hiking (01分数规划)

    http://codeforces.com/contest/489/problem/E E. Hiking time limit per test 1 second memory limit per ...

  3. Codeforces Round #277.5 (Div. 2)-D. Unbearable Controversy of Being

    http://codeforces.com/problemset/problem/489/D D. Unbearable Controversy of Being time limit per tes ...

  4. Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...

    http://codeforces.com/problemset/problem/489/C C. Given Length and Sum of Digits... time limit per t ...

  5. Codeforces Round #277.5 (Div. 2)-B. BerSU Ball

    http://codeforces.com/problemset/problem/489/B B. BerSU Ball time limit per test 1 second memory lim ...

  6. Codeforces Round #277.5 (Div. 2)-A. SwapSort

    http://codeforces.com/problemset/problem/489/A A. SwapSort time limit per test 1 second memory limit ...

  7. Codeforces Round #277.5 (Div. 2) A,B,C,D,E,F题解

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud A. SwapSort time limit per test    1 seco ...

  8. Codeforces Round #277.5 (Div. 2)-D

    题意:求该死的菱形数目.直接枚举两端的点.平均意义每一个点连接20条边,用邻接表暴力计算中间节点数目,那么中间节点任选两个与两端可组成的菱形数目有r*(r-1)/2. 代码: #include< ...

  9. Codeforces Round #277.5 (Div. 2)B——BerSU Ball

    B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. Oracle约束(Constraint)详解

    概述 约束是数据库用来确保数据满足业务规则的手段,不过在真正的企业开发中,除了主键约束这类具有强需求的约束,像外键约束,检查约束更多时候仅仅出现在数据库设计阶段,真实环境却很少应用,更多是放到程序逻辑 ...

  2. MyBlog

    2016-06-25 一直想在搭建一个自己的blog.说来惭愧,cnblogs中的个人博客虽笔耕不辍,但杂乱无章.然而之前总是嘴上说说.现在,终于要行动起来了. 初步计划: 思路: django + ...

  3. px,em,rem

    px:像素是相对于显示器屏幕分辨率而言的相对长度单位.pc端使用px倒也无所谓,可是在移动端,因为手机分辨率种类颇多,不可能一个个去适配,这时px就显得非常无力,所以就要考虑em和rem. em:继承 ...

  4. UVALive 4870 Roller Coaster --01背包

    题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F ,     D -= K 问在D小于等于一定限度的时 ...

  5. Hibernate第三次测试错题解析

    此题目考查的是Hibernate查询缓存适用的场合,对于经常使用的查询语句, 如果启用了查询缓存,当第一次执行查询语句时,Hibernate会把查询结果存放在第二缓存中. 以后再次执行该查询语句时,只 ...

  6. etl实现字段值相加

    数据库USERS表: etl步骤: (2) (3) 其中java代码为: import test.Test;          public boolean processRow(StepMetaIn ...

  7. JS中变量名和函数名重名

    今天骚凯问了一道变量名冲突的题目,感觉很有意思,顺便也复习一下预解析的一些知识,有不对的地方忘前辈大神指正,题目是这样的: var a=100; function a(){ console.log(a ...

  8. Git的Patch功能

    转自:http://www.cnblogs.com/y041039/articles/2411600.html UNIX世界的软件开发大多都是协作式的,因此,Patch(补丁)是一个相当重要的东西,因 ...

  9. 关于Advanced Installer 11.0打包软件过程一些记录

    1.想要安装后在默认网站下为一个虚拟目录,IIs,Web应用程序,选中虚拟目录是一个Web应用程序.同时修改常规>文件夹,重新指向网站文件所在目录,不然会少一级目录 2.如果想单独的应用程序池, ...

  10. ZooKeeper 笔记(1) 安装部署及hello world

    先给一堆学习文档,方便以后查看 官网文档地址大全: OverView(概述) http://zookeeper.apache.org/doc/r3.4.6/zookeeperOver.html Get ...