A

题意:给出一个数n,求满足a+b=n,且a+b均为合数的a,b

方法一:可以直接枚举i,n-i,判断a,n-i是否为合数

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
bool isp[]; void isprime(){
isp[]=isp[]=true;
for(int i=;i<=;i++){
if(isp[i]==false)
for(int j=i*;j<=;j+=i)
isp[j]=true;
}
} int main()
{
int n;
cin>>n;
isprime();
for(int i=;i<=n;i++){
if(isp[i]&&isp[n-i]){
printf("%d %d\n",i,n-i);
break;
}
}
return ;
}

方法二:注意到n>=12,而4是最小的合数,

所以:当n为奇数的时候,那么n-9至少是为4的合数,输出9,n-9

当n为偶数的时候,那么n-8至少是为4的合数,输出8,n-8

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL; int main(){
int n;
cin>>n;
if(n%) printf("%d %d\n",,n-);
else printf("%d %d\n",,n-);
return ;
}

B

题意:给出一个电梯,给出n个人,n个人要上到的楼层a[i],以及电梯每次最多能装载的人数k,问把每个人都送到目标楼层,需要花费的最少时间

看的出题人的题解:先是第一组k个人和这k个人里面要去往的楼层最高的人乘同一次电梯,再是第二组k个人和这k个人里面要去往的楼层最高的人乘同一次电梯,

所以总时间为ans=2*((a[n]-1)+(a[n-k]-1)+a[n-2k]-1)----

所以先排序,再倒着取依次取第k个数,这样能够尽量减少下一次运送人的时间, 出题人的证明没有看明白= =

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
int a[]; int main(){
int n,k,i,j,ans=;
cin>>n>>k;
for(i=;i<=n;i++) cin>>a[i];
sort(a+,a+n+);
for(i=n;i>=;i=i-k){
ans+=(a[i]-)*;
}
printf("%d\n",ans);
return ;
}

C

题意:给出n个人的姓,和名,任意选择其中一个作为排序的关键字,问能否满足给出的序列。

按照给出的序列来遍历,先将a[i],b[i]排序成小的在前,大的在后,如果a[i]大于当前的cur,那么将a[i]赋值给cur,否则b[i]赋给cur,都不满足的话则是“NO” 就是尽量选择a[i],b[i]中更小的作为关键字

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
string a[],b[];
int p[];
string cur=""; int main()
{
int n,i,j;
cin>>n;
for(i=;i<n;i++) cin>>a[i]>>b[i];
for(i=;i<n;i++) {
cin>>p[i];
p[i]--;
} for(i=;i<n;i++){
int x=p[i];
if(a[x]>b[x]) swap(a[x],b[x]);
if(cur<a[x]) cur=a[x];
else if(cur<b[x]) cur=b[x];
else{
printf("NO\n");
return ;
}
}
printf("YES\n");
return ;
}

D

题意:给出一个矩阵,问这个矩阵是否能由一颗带权值的树构成

先用prim建树,再依次枚举每一个节点到其他节点的距离,看是否和给出的矩阵一样

还不懂写= =

Codeforces Round #270的更多相关文章

  1. Codeforces Round #270 1003

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

  2. Codeforces Round #270 1002

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

  3. Codeforces Round #270 1001

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

  4. Codeforces Round #270 A~D

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

  5. Codeforces Round #270(利用prim算法)

    D. Design Tutorial: Inverse the Problem time limit per test 2 seconds memory limit per test 256 mega ...

  6. codeforces水题100道 第七题 Codeforces Round #270 A. Design Tutorial: Learn from Math (math)

    题目链接:http://www.codeforces.com/problemset/problem/472/A题意:给你一个数n,将n表示为两个合数(即非素数)的和.C++代码: #include & ...

  7. 多种方法过Codeforces Round #270的A题(奇偶法、打表法和Miller_Rabin(这个方法才是重点))

    题目链接:http://codeforces.com/contest/472/problem/A 题目: 题意:哥德巴赫猜想是:一个大于2的素数一定可以表示为两个素数的和.此题则是将其修改为:一个大于 ...

  8. Codeforces Round #270 D Design Tutorial: Inverse the Problem --MST + DFS

    题意:给出一个距离矩阵,问是不是一颗正确的带权树. 解法:先按找距离矩阵建一颗最小生成树,因为给出的距离都是最短的点间距离,然后再对每个点跑dfs得出应该的dis[][],再对比dis和原来的mp是否 ...

  9. Codeforces Round #270 D C B A

    谈论最激烈的莫过于D题了! 看过的两种做法不得不ORZ,特别第二种,简直神一样!!!!! 1th:构造最小生成树. 我们提取所有的边出来按边排序,因为每次我们知道边的权值>0, 之后每次把边加入 ...

随机推荐

  1. SQL SERVER时间函数

    本篇文章还是学习<程序员的SQL金典>内容的记录,此次将讲解的是SQL SERVER的时间函数. 本文只讲SQL SERVER支持的时间函数(其它数据库这里就不罗列了,想看更多的可以关注& ...

  2. 时隔8年HTML 5终于定稿!

    我们第一次谈论 HTML5 要改变世界大概是因为乔布斯,他坚持在 iOS 上不兼容 Flash,在 Adobe 统治多媒体开发的那个年代,这需要付出极大的勇气.这么多年过去了,虽然所有人都在谈论 HT ...

  3. 【POJ】【1067】取石子游戏

    博弈论 这个是博弈游戏中的Wythoff博弈: 以下为我的代码: //POJ 1067 #include<cmath> #include<cstdio> #include< ...

  4. 2012 Asia JinHua Regional Contest

    Draw Something http://acm.hdu.edu.cn/showproblem.php?pid=4450 o(n)统计输入每个数的平方和. #include<cstdio> ...

  5. 原码 & 反码 & 补码 & 详解

    本篇文章讲解了计算机的原码, 反码和补码. 并且进行了深入探求了为何要使用反码和补码, 以及更进一步的论证了为何可以用反码, 补码的加法计算原码的减法. 论证部分如有不对的地方请各位牛人帮忙指正! 希 ...

  6. ural 1864

    题意描述不清   而且还卡精度 ~~ #include <cstdio> #include <cstring> #include <iostream> using ...

  7. c# 4.0新特性一览

    原文:http://www.cnblogs.com/palo/archive/2009/03/01/1400949.html 终于静下心来仔细听了一遍Anders Hejlsberg(Visual S ...

  8. ubuntu安装hadoop2.6

    一:单机版 1.sudo gedit ~/.bashrc 加入JDK路径 #HADOOP VARIABLES START export JAVA_HOME=/usr/lib/jvm/java-1.7. ...

  9. linux软中断与硬中断实现原理概述

    linux软中断与硬中断实现原理概述. 1.软中断通过open_softirq注册一个软中断处理函数,即在软中断向量表softirq_vec数组中添加新的软中断处理action函数. 2.调用rais ...

  10. Sina App Engine(SAE)入门教程(4)- SaeVCode(验证码服务)使用

    参考资料 SaeVCode api 文档 使用教程 所有的验证码原理都是生成一个vcode字符串,存到session中,和用户的输入进行比较判断,以下是一个使用验证码服务的完整实例: 首页index. ...