Codeforces Round #270
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的更多相关文章
- Codeforces Round #270 1003
Codeforces Round #270 1003 C. Design Tutorial: Make It Nondeterministic time limit per test 2 second ...
- Codeforces Round #270 1002
Codeforces Round #270 1002 B. Design Tutorial: Learn from Life time limit per test 1 second memory l ...
- Codeforces Round #270 1001
Codeforces Round #270 1001 A. Design Tutorial: Learn from Math time limit per test 1 second memory l ...
- Codeforces Round #270 A~D
Codeforces Round #270 A. Design Tutorial: Learn from Math time limit per test 1 second memory limit ...
- Codeforces Round #270(利用prim算法)
D. Design Tutorial: Inverse the Problem time limit per test 2 seconds memory limit per test 256 mega ...
- codeforces水题100道 第七题 Codeforces Round #270 A. Design Tutorial: Learn from Math (math)
题目链接:http://www.codeforces.com/problemset/problem/472/A题意:给你一个数n,将n表示为两个合数(即非素数)的和.C++代码: #include & ...
- 多种方法过Codeforces Round #270的A题(奇偶法、打表法和Miller_Rabin(这个方法才是重点))
题目链接:http://codeforces.com/contest/472/problem/A 题目: 题意:哥德巴赫猜想是:一个大于2的素数一定可以表示为两个素数的和.此题则是将其修改为:一个大于 ...
- Codeforces Round #270 D Design Tutorial: Inverse the Problem --MST + DFS
题意:给出一个距离矩阵,问是不是一颗正确的带权树. 解法:先按找距离矩阵建一颗最小生成树,因为给出的距离都是最短的点间距离,然后再对每个点跑dfs得出应该的dis[][],再对比dis和原来的mp是否 ...
- Codeforces Round #270 D C B A
谈论最激烈的莫过于D题了! 看过的两种做法不得不ORZ,特别第二种,简直神一样!!!!! 1th:构造最小生成树. 我们提取所有的边出来按边排序,因为每次我们知道边的权值>0, 之后每次把边加入 ...
随机推荐
- C#之多态
多态是面向对象编程中三大机制之一,其原理建立在"从父类继承而来的子类可以转换为其父类"这个规则之上,换句话说,能用父类的地方,就能用该类的子类.当从父类派生了很多子类时,由于每个子 ...
- w3c_html_study_note_5.26
xhtml+css 正确的说法 “DIV+CSS”叫法将网页制作者引入两大误区 [误区一]网页中用了Table,页面就不标准,甚至觉着用Table丢人,Table成为了判定页面是否标准的关键点. [误 ...
- Jquery 查看DOM上绑定的事件列表
$(dom).data( "events" ); 包括事件类型和关联的处理函数 下面是firefox的截图
- 针对谷歌默认最小字体12px的正确解决方案 (css、html)
今天晨会,产品要求把以前12px的字体改小一点,我心想这有什么难的,就随口答应了.哪知,改css的时候,谷歌浏览器中font-size小于12px时,字体就不会再缩小了.当时我的第一反应就是会不会是其 ...
- Codeforces Round #363 (Div. 2)->A. Launch of Collider
A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- PHP之preg_replace()与ereg_replace()正则匹配比较讲解
<?php //preg_replace()和ereg_replace()函数的使用的比较 // -------preg_replace()-------------------------- ...
- make -f dc_debug.mak 提示错误"/usr/bin/ld:can not find -l***"解决办法
在公司不同服务器上"make -f ***"程序的时候,有的服务器可以编译通过,有的却提示"/usr/bin/ld:can not find -l***"的错误 ...
- 6 个基于 jQuery 的表单向导插件推荐
表单向导可以很好地引导用户进行一步一步的操作,从而降低用户错误输入的几率.尽管互联网中有大量的类似插件,但真正好用的不多. 本文整理了6个比较优秀的表单向导插件,希望能够为你带来帮助. 1. Smar ...
- Window 8.1 开启Wifi共享
p{padding-left:20px;} Hosted network supported:Yes 支持Wifi共享 命令:netsh wlan set hostednetwork mode=al ...
- linux上部署应用
1.编写traffic.sh 引入相关的jar包及java环境路径 2.crontab -e 加入: */10 * * * * cd /opt/sys/traffic_version/bin & ...