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. ADT eclipse打开时出现Error: Error parsing C:\Users\admin*\.android\devices.xml

    Error: Error parsing C:\Users\admin*\.android\devices.xml  在ADT eclipse打开项目的时候出现此提示,但是又不影响使用. 原因:之前安 ...

  2. Understand User's Intent from Speech and Text

    http://research.microsoft.com/en-us/projects/IntentUnderstanding/ Understanding what users like to d ...

  3. eclipse 下找不到或无法加载主类的解决办法[转]

    转自:http://blog.sina.com.cn/s/blog_7ebc46500101gtff.html 有时候 Eclipse 会发神经,好端端的 project 就这么编译不了了,连 Hel ...

  4. kali linux安装vm

    https://download3.vmware.com/software/wkst/file/VMware-Workstation-Full-10.0.2-1744117.i386.bundle v ...

  5. 17.2 The DispatcherServlet

    综述: Spring’s web MVC framework is, like many other web MVC frameworks, request-driven, designed arou ...

  6. 解决java写入xml报错org.w3c.dom.DOMException:DOM002 Illeg

    Exception is -- > org.w3c.dom.DOMException: DOM002 Illegal character 字符不被允许 org.w3c.dom.DOMExcept ...

  7. 字符串匹配--kmp算法原理整理

    kmp算法原理:求出P0···Pi的最大相同前后缀长度k: 字符串匹配是计算机的基本任务之一.举例,字符串"BBC ABCDAB ABCDABCDABDE",里面是否包含另一个字符 ...

  8. jquery加入收藏代码

    <html> <head> <script type="text/javascript" src="jquery-1.9.1.js" ...

  9. linux入门教程(六) Linux文件与目录管理

    在linux中什么是一个文件的路径呢,说白了就是这个文件存在的地方,例如在上一章提到的/root/.ssh/authorized_keys 这就是一个文件的路径.如果你告诉系统这个文件的路径,那么系统 ...

  10. 套题T2

    数学(math.cpp) DXY的数学很差... 对于所有1<=i<=N求(2^i – i^2)能被7整除的个数.(N<=1000000) 样例输入: 3 样例输出: 1 你在代码中 ...