http://codeforces.com/contest/459

A题 Pashmak and Garden

化简化简水题,都告诉平行坐标轴了,数据还出了对角线,后面两个点坐标给的范围也不错

#include <cstdio>
int x[4],y[4];
int abs(int n){
return n<0?-n:n;
}
int main(){
scanf("%d%d%d%d",x,y,x+1,y+1);
int dx=abs(x[0]-x[1]);
int dy=abs(y[0]-y[1]);
if(dx*dy==0&&dx!=dy){
printf("%d %d %d %d\n",x[0]+dy,y[0]+dx,x[1]+dy,y[1]+dx);
}
else if(dx==dy&&dx!=0){
printf("%d %d %d %d\n",x[1],y[0],x[0],y[1]);
}
else printf("-1\n");
return 0;
}

  B:Pashmak and Flowers

被hack的一次出在long long

#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int maxt=-1,mint=0x7fffffff;
long long maxn=0,minn=0;
int main(){
scanf("%d",&n);
long long ans;
for(int i=0;i<n;i++){
int temp;
scanf("%d",&temp);
if(temp>maxt){
maxt=temp;
maxn=1;
}
else if(temp==maxt)maxn++;
if(temp<mint){
mint=temp;minn=1;
}
else if(temp==mint)minn++;
}
if(maxt==mint)ans=maxn*(minn-1)/2;
else ans=minn*maxn;
printf("%d %I64d\n",maxt-mint,ans);
return 0;
}

  

C:Pashmak and Buses

纯鸽笼,就是看看有没有n>k的情况就好,每次看这次分到一个鸽笼的数目

#include <cstdio>
using namespace std;
int n,k,d;
int ind[1001];
int main(){
scanf("%d%d%d",&n,&k,&d);
for(int i=1;i<=1000;i++)ind[i]=i;
int tn=1;
for(int td=0;td<d;td++){tn*=k;if(tn>n)break;}//为了防爆int
if(tn<n)puts("-1");
else for(int td=0;td<d;td++){
for(int i=0;i<n;i++){
printf("%d%c",ind[i]%k+1,i==n-1?'\n':' ');
ind[i]=(ind[i]+k-1)/k;
}
tn=(tn+k-1)/k;
}
return 0;
}

D:Pashmak and Parmida's problem

map统计+树状数组

每从右边(f(j)小)更新答案(sum(f(i)-1)到1)的时候把f(j)加进树状数组就行了

#pragma pack(1)
#include <cstdio>
#include <map>
using namespace std;
map<int,int> mp;
int a[1000000],bit[1000000],pr[1000000];//看成1e5错一回
long long ans;
int n;
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",a+i);
pr[i]=mp[a[i]]++;
}
for(int i=n-1;i>-1;i--){
for(int j=pr[i];j!=0;j-=(j&-j))ans+=bit[j];
for(int j=mp[a[i]]-pr[i];j<n;j+=(j&-j)){bit[j]++;}
}
printf("%I64d\n",ans);
return 0;
}

 E:Pashmak and Graph

dp,要注意的是同一个cost值可能发生相互修改的情况,所以拷贝出来再拷贝回去

 

#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=3e5+1;
struct edge{
int f,t,c;
bool operator <(const edge & e2) const {
return c<e2.c;
}
}e[maxn];
int n,m;
int dp[maxn],tt[maxn],pre[maxn];
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)scanf("%d%d%d",&e[i].f,&e[i].t,&e[i].c);
sort(e,e+m);
int j;
for(int i=0;i<m;i=j){
int cnt=0;
for(j=i;j<m&&e[j].c==e[i].c;j++){
pre[cnt]=dp[e[j].f]+1;
tt[cnt++]=e[j].t;
}
while(cnt-->=0){
dp[tt[cnt]]=max(dp[tt[cnt]],pre[cnt]);
}
}
int ans=0;
for(int i=1;i<=n;i++)ans=max(ans,dp[i]);
printf("%d\n",ans);
return 0;
}

  这是更好的姿势,边dp,点更新

#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=3e5+1;
const int maxm=3e5+1;
struct edge{
int f,t,c;
bool operator <(const edge & e2) const {
return c<e2.c;
}
}e[maxm];
int n,m;
int dp[maxm],tc[maxn];
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)scanf("%d%d%d",&e[i].f,&e[i].t,&e[i].c);
sort(e,e+m);
int j=0;
for(int i=0;i<m;i++){
while(e[j].c<e[i].c){
tc[e[j].t]=max(dp[j],tc[e[j].t]),j++;
}
dp[i]=tc[e[i].f]+1;//learning
}
int ans=0;
for(int i=0;i<m;i++)ans=max(ans,dp[i]);
printf("%d\n",ans);
return 0;
}

  

CF 459A && 459B && 459C && 459D && 459E的更多相关文章

  1. CF 459A(Pashmak and Garden-正方形给出2点求2点)

    A. Pashmak and Garden time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. cf 459c Pashmak and Buses

    E - Pashmak and Buses Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  3. cf 459E

    cf459E 这题说的是 给定一个n点m条边的带边权的有向图,从中找出一条路径(可以带环),该路径包含的边数最多,并且要求路径中的权值必须严格递增,然后对边进行排序完个后采用dp去解特殊判断一下边权值 ...

  4. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  5. codeforces 459E

    codeforces 459E E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabyte ...

  6. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  7. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  8. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  9. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

随机推荐

  1. NOIP Mayan游戏 - 搜索

    Mayan puzzle是最近流行起来的一个游戏.游戏界面是一个7行5列的棋盘,上面堆放着一些方块,方块不能悬空堆放,即方块必须放在最下面一行,或者放在其他方块之上.游戏通关是指在规定的步数内消除所有 ...

  2. noip 2012 提高组 day2 部分题解

    这道题有多种解法,我用的是扩展欧几里得算法求到的答案 #include<iostream> #include<fstream> #include<cstdio> u ...

  3. C#调用系统蜂鸣(需要发出警告时挺好用的 即使没有声卡)

    http://heavenslv.iteye.com/blog/1033870 // 声明 public class BeepUp { /// <param name="iFreque ...

  4. YOLOv1-darknet 内容解析

    目录 YOLOv1-darknet 内容解析 1. 核心思想 2. 特点 3. 缺点 4. 算法流程 5. 详细内容 6. 主要参考 YOLOv1-darknet 内容解析 1. 核心思想 目标检测分 ...

  5. HDU 6143 Killer Names(容斥原理)

    http://acm.hdu.edu.cn/showproblem.php?pid=6143 题意: 用m个字母去取名字,名字分为前后两部分,各由n个字符组成,前后两部分不能出现相同字符,问合法的组成 ...

  6. python 元组元素计数

    #create a tuple tuplex = , , , , , , , , print(tuplex) #return the number of times it appears in the ...

  7. Jenkins 构建 coding项目,插件

    安装插件:http://updates.jenkins-ci.org/download/plugins/coding-webhook/

  8. MongoDB(课时11 嵌套集合)

    3.4.2.6 嵌套集合运算 MongoDB数据库里每个集合数据可以继续保存其它的集合数据.例如:有些学生信息中需要保存家长信息. 范例: 增加数据 db.students.insert({" ...

  9. map/multimap_01

    标准的关联式容器 键值对序列 基于key的快速检索能力 key按序排列,按序插入 红黑树变体的平衡二叉树 对key来说支持 mapT[key] 和 mapT.at(key) multimap 不支持  ...

  10. Android仿QQ微信开场导航以及登陆界面

    相信大家对于微信等社交应用的UI界面已经都很熟悉了,该UI最值得借鉴的莫过于第一次使用的时候一些列产品介绍的图片,可以左右滑动浏览,最后 进入应用,这一效果适用于多种项目中,相信今后开发应用一定会用得 ...