Codeforces Round #270

A - Design Tutorial: Learn from Math

题意:给出n,求出两个合数x和y使x+y=n。

题解:暴力筛合数,然后暴力找

 //#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 ll __int64
#define usint unsigned int
#define mz(array) memset(array, 0, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,x,n) for(int 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("1.out","w",stdout) bool a[]; int main() {
int x,i,n,j;
RD(n);
int n2=n/;
for(x=; x<=n2; x++) {
if(a[x]==) {
for(i=x+x; i<=n; i+=x) {
a[i]=;
}
}
}
for(x=;x<=n2;x++){
if(a[x]== && a[n-x]==)break;
}
printf("%d %d\n",x,n-x);
return ;
}

B - Design Tutorial: Learn from Life

题意:一堆人从1楼坐电梯,电梯一次最多装K人,给出各个人要去的各个楼层,上下电梯时间忽略不计,电梯移动一层需要1秒,求最少需要多少时间才能送完所有人并且电梯回到1楼。

题解:贪心,优先送最高的,空位顺便送低的。

 //#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 ll __int64
#define usint unsigned int
#define mz(array) memset(array, 0, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,x,n) for(int 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("1.out","w",stdout) int a[]; int main() {
int n,k,i,j,x,ans;
RD2(n,k);
REP(i,n) {
RD(x);
a[x]++;
}
x=;
ans=;
for(i=;i>=;i--) {
if(a[i]>) {
a[i]-=x;
int t=a[i]/k;
int tt=t*k;
int ttt=tt>=a[i]?t:t+;
ans+=ttt*(i-)*;
x=ttt*k-a[i];
//printf("%d %d %d\n",i,ttt,ans);
}
}
WN(ans);
return ;
}

C - Design Tutorial: Make It Nondeterministic

题意:每个人可以用自己的姓或者名字作为ID,给出各个人的名字,给出一个排名序列,若有一种选择ID的方法可以使排名正确,则输出YES,否则输出NO。

题解:贪心,排名1的人选字典序少的那个,然后都优先选字典序小的,不行了就选大的,再不行就NO。

 //#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 ll __int64
#define usint unsigned int
#define mz(array) memset(array, 0, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,x,n) for(int 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("1.out","w",stdout) char s[][][]; int cmp(char a[],char b[]) {
int la=strlen(a),lb=strlen(b);
int l=min(la,lb);
int i;
for(i=; i<l; i++) {
if(a[i]>b[i])return ;
if(b[i]>a[i])return -;
}
if(la>lb)return ;
if(lb>la)return -;
return ;
} int main() {
int n;
RD(n);
REP(i,n) {
scanf(" %s%s",s[i][],s[i][]);
//printf("%d %s!%s!\n",i,s[i][0],s[i][1]);
}
char q[];
int x,y=,z,j;
RD(x);
y=x-;
if(cmp(s[y][],s[y][])==-) z=;
else z=;
bool flag=;
REP(i,n-) {
RD(x);
x--;
if(cmp(s[x][],s[x][])==-) j=;
else j=;
if(cmp(s[x][j] , s[y][z])==-){
if(cmp(s[x][j^], s[y][z])==-){
flag=;
break;
}else{
y=x;
z=j^;
}
}else{
y=x;
z=j;
}
}
if(flag)puts("YES");
else puts("NO");
return ;
}

D - Design Tutorial: Inverse the Problem

题意:给出各个点距离的邻接矩阵,判断这是不是一棵树。

题解:先根据样例特判一些情况,然后最小生成树,我是用可撸斯卡尔,当要加入的边的两个点x和y已经在同一集合,则判它们的距离是否正确。我的方法是找到一个中间点v,使x-v和v-y有路,找到(xv距离) + (vy距离)最小的那个值,当作x到y的距离。这是因为可撸斯卡尔是从小往大加边,肯定有至少一个中间点能使得这个有路。复杂度O(n^3),略高,姿势不对就要TLE……更好的解法可以看这里:http://www.cnblogs.com/forgot93/p/4000850.html

 //#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 ll __int64
#define usint unsigned int
#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(int i=0;i<(n);i++)
#define FOR(i,x,n) for(int 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("1.out","w",stdout)
const int inf=*1e9+;
const int maxn=;
const int maxm=maxn*maxn; int a[][];
int n; int bx[maxm],by[maxm],bz[maxm];
int bn;
inline void add(const int &x,const int &y,const int &z){
bx[bn]=x;
by[bn]=y;
bz[bn]=z;
bn++;
} int d[maxm];
bool cmp(const int &x,const int &y){
return bz[x]<bz[y];
} int f[maxm];
int gf(const int &x){
if(f[x]==-)return x;
f[x]=gf(f[x]);
return f[x];
} struct Edge{
int next,v,l;
}e[maxm];
int head[maxn],en; inline void addedge(const int &x,const int &y,const int &z){
e[en].v=y;
e[en].l=z;
e[en].next=head[x];
head[x]=en;
en++;
} int dis[maxn][maxn]; inline void gank(const int &x,const int &y){
int mi=inf;
for(int i=head[x];i!=-;i=e[i].next){
if(dis[y][e[i].v]!=-){
//printf("(%d) %d + %d = %d\n",e[i].v,e[i].l,dis[y][e[i].v],e[i].l + dis[y][e[i].v]);
mi=min(mi , e[i].l + dis[y][e[i].v]);
}
}
dis[y][x]=dis[x][y]=mi;
} bool farm(){
int i,j,k,x,y,z;
bn=;
REP(i,n){
REP(j,n){
if(i!=j){
if(a[i][j]==)return ;
}else{
if(a[i][j]!=)return ;
}
}
}
REP(i,n){
REP(j,i){
if(a[i][j]!=a[j][i])return ;
add(i,j,a[i][j]);
}
}
REP(i,bn){
d[i]=i;
}
sort(d,d+bn,cmp);
mf1(f);
//mf1(head);
REP(i,n)REP(j,n)dis[i][j]=-;
en=;
mf1(head);
REP(i,n)dis[i][i]=;
//en=0;
REP(i,bn){
int q=d[i];
int &x=bx[q],&y=by[q],&z=bz[q];
int fx=gf(x),fy=gf(y);
if(fx!=fy){
addedge(x,y,z);
addedge(y,x,z);
dis[x][y]=z;
dis[y][x]=z;
f[fx]=fy;
}else{
if(dis[x][y]==-) gank(x,y);
//printf("dis[%d][%d]=%d , z=%d\n",x,y,dis[x][y],z);
if(dis[x][y]!=z)return ;
}
}
return ;
} int main() {
int i;
RD(n);
REP(i,n)REP(j,n) RD(a[i][j]);
if(farm())puts("YES");
else puts("NO");
return ;
}

codeforces #270 ABCD的更多相关文章

  1. Codeforces #270 D. Design Tutorial: Inverse the Problem

    http://codeforces.com/contest/472/problem/D D. Design Tutorial: Inverse the Problem time limit per t ...

  2. Codeforces Round #270 1003

    Codeforces Round #270 1003 C. Design Tutorial: Make It Nondeterministic time limit per test 2 second ...

  3. Codeforces Round #270 1002

    Codeforces Round #270 1002 B. Design Tutorial: Learn from Life time limit per test 1 second memory l ...

  4. Codeforces Round #270 1001

    Codeforces Round #270 1001 A. Design Tutorial: Learn from Math time limit per test 1 second memory l ...

  5. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  6. Codeforces Round #270 A~D

    Codeforces Round #270 A. Design Tutorial: Learn from Math time limit per test 1 second memory limit ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  9. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

随机推荐

  1. Android成长日记-Android四大组件之Service组件的学习

    1.什么是Service? Service是Android四大组件中与Activity最相似的组件,它们都代表可执行的程序,Service与Activity的区别在于:Service一直在后台运行,它 ...

  2. Android成长日记-WebView使用

    在App中有时候会看到一些页面是以网页的形式展示,其原理就是运用了WebView,下面予以讲述WebView 1. 使用Intent调用系统浏览器或者第三方浏览器打开网页 调用系统浏览器打开页面 Ur ...

  3. Unity 依赖注入知识点

    三种依赖注入方法,构造器注入.属性注入.方法注入 可以配置Config文件,来实现不用修改代码.需要先将接口与实体关联,然后使用时会自动加载对应实体. namespace WeChatConsole ...

  4. TypeScript Basic Types(基本类型)

    在学习TypeScript之前,我们需要先知道怎么才能让TypeScript写的东西正确的运行起来.有两种方式:使用Visual studio 和使用 NodeJs. 这里我选择的是NodeJs来编译 ...

  5. JavaScript制作时钟特效

    需求说明:制作显示年.月.日.星期几并且显示上午(AM)和下午(PM)的 12进制的时钟,具体效果如下所示: 代码如下: <!DOCTYPE HTML PUBLIC "-//W3C// ...

  6. 【Alpha版本】 第五天 11.11

    一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 昨天完成任务 今天完成任务 周末+下周一要做任务 问题困难 心得体会 胡泽善 完成了账户信息修改界面 完成管理员的三大界面框架.完成管理 ...

  7. mysql 某周的起始和结束日期

    转自:http://bbs.csdn.net/topics/370096126 t_table有数据如下:year    Week2011    22011    32011    42011     ...

  8. primefaces p:dataExporter filename 支持中文 utf8

    p:fileDownload and p:dataExporter : for p:fileDownload, the Content-Disposition header should be set ...

  9. 《JavaScript权威指南》学习笔记 第二天 下好一盘大棋

    前段学习js的时候总是零零散散的,以至于很多东西都模棱两可.时间稍微一久,就容易忘记.最主要的原因是这些东西,原来学的时候就不是太懂,以至于和其他知识无法形成记忆链,所以孤零零的知识特别容易忘记.重温 ...

  10. 高可用与负载均衡(1)之linux系统的数据链路层负载均衡

    preface 在蓝厂就职到时候,每台缓存服务器都能够跑到2G的流量,这么大的流量,有人会问,服务器是不是安装的万兆网卡,no no no,仅仅是3张千兆网卡绑定在一块.万兆网卡的服务器少见,大多数都 ...