Codeforces Round #277.5 (Div. 2) ABCDF
http://codeforces.com/contest/489
# | 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的更多相关文章
- Codeforces Round #277.5 (Div. 2)
题目链接:http://codeforces.com/contest/489 A:SwapSort In this problem your goal is to sort an array cons ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #277.5 (Div. 2)-D
题意:求该死的菱形数目.直接枚举两端的点.平均意义每一个点连接20条边,用邻接表暴力计算中间节点数目,那么中间节点任选两个与两端可组成的菱形数目有r*(r-1)/2. 代码: #include< ...
- 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 ...
随机推荐
- NEST与JSON语法对照 一 match与multi_match
{ "query": { "bool": { "must": [ { "multi_match": { "qu ...
- 【小白的CFD之旅】07 CFD常识
学了一周的流体力学,小白对于流体力学有了基本的了解,但是流体力学涵盖的内容何其之多,一周的时间怎么可能学得好呢,很多的概念都是模棱两可.为了在一个月之后能够应用CFD,小白又找到了黄师姐. “师姐,看 ...
- C#使用正则表达式检测数字 char 和韩文
if (!System.Text.RegularExpressions.Regex.IsMatch(strRoleName[i].ToString(), @"^[\uac00-\ud7ff] ...
- Python的with用法理解
Python的with理解 标签(空格分隔): Python with做为一种上下文管理器,在Python中的作用可以简单的理解为是用来代替try...except...finally的处理流程. w ...
- Codeforces Training S03E01泛做
http://codeforces.com/gym/101078 和ysy.方老师一起打的virtual 打的不是很好...下面按过题顺序放一下过的题的题(dai)解(ma). A 给两个1~n的排列 ...
- 踩坑所引发出的appendChild方法的介绍
问题描述 最近在做项目时,遇到一个问题,当js生成一个组件后,会注入到页面的某个节点里显示.在组件内部进行了一次注入操作,在调用组件的外部js文件中也进行了一次注入操作,结果发现页面里只生成了一份组件 ...
- jQuery基础课程
环境搭建 搭建一个jQuery的开发环境非常方便,可以通过下列几个步骤进行. 下载jQuery文件库 在jQuery的官方网站(http://jquery.com)中,下载最新版本的jQuery文件库 ...
- java中hashcode()和equals()的详解
今天下午研究了半天hashcode()和equals()方法,终于有了一点点的明白,写下来与大家分享(zhaoxudong 2008.10.23晚21.36). 1. 首先equals()和hashc ...
- 使用对话框 —— Dialog
对话框就是一般的弹出窗口,主要用来提示用户,和用户交互. 创建Activity对话框 使用Activity模拟对话框.这个比较简单,主要是使用Activity自带的Dialog主题. 创建 ...
- sendEmail
原文:http://blog.chinaunix.net/uid-16844903-id-308853.html 功能: 发邮件的客户端 官网地址: http://caspian.dotconf.ne ...