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. android studio 不能在线更新android SDK Manager问题解决办法

    Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: Connecti ...

  2. [转载]C# FTP操作工具类

    本文转载自<C# Ftp操作工具类>,仅对原文格式进行了整理. 介绍了几种FTP操作的函数,供后期编程时查阅. 参考一: using System; using System.Collec ...

  3. 3244: [Noi2013]树的计数 - BZOJ

    Description 我们知道一棵有根树可以进行深度优先遍历(DFS)以及广度优先遍历(BFS)来生成这棵树的DFS序以及BFS序.两棵不同的树的DFS序有可能相同,并且它们的BFS序也有可能相同, ...

  4. 【BZOJ】【3757】苹果树

    树分块 orz HZWER http://hzwer.com/5259.html 不知为何我原本写的倍增求LCA给WA了……学习了HZWER的倍增新姿势- 树上分块的转移看vfk博客的讲解吧……(其实 ...

  5. C# WinForm开发系列 - ZedGraph

    ZedGraph是用于创建任意数据的二维线型.条型.饼型图表的一个类库,也可以作为Windows窗体用户控件和Asp.Net网页控件.这个类库具有高度的适应性,几乎所有式样的图表都能够被创建.这个类库 ...

  6. ios开发之网络基础

    1.网络访问的步骤 1> 建立NSURL 2> 建立NSURLRequest 3> 建立NSURLConnection 4> 开始连接 - (void)viewDidLoad ...

  7. Synchronized Methods

    Synchronized Methods The Java programming language provides two basic synchronization idioms: synchr ...

  8. 黑马程序员-C#学习笔记(二)

    ---------------------- ASP.Net+Android+IOS开发..Net培训.期待与您交流! ---------------------- - C# 学习笔记 一.变量与表达 ...

  9. Spark Mllib逻辑回归算法分析

    原创文章,转载请注明: 转载自http://www.cnblogs.com/tovin/p/3816289.html 本文以spark 1.0.0版本MLlib算法为准进行分析 一.代码结构 逻辑回归 ...

  10. 关于in与exists的效率讨论

    关于in与exists的效率讨论1).select * from A where id in (select id from B)以上查询使用了in语句,in只执行一次,他查出B表的所有id字段并缓存 ...