CF 459A && 459B && 459C && 459D && 459E
http://codeforces.com/contest/459
化简化简水题,都告诉平行坐标轴了,数据还出了对角线,后面两个点坐标给的范围也不错
#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;
}
被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;
}
纯鸽笼,就是看看有没有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;
}
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的更多相关文章
- 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 ...
- cf 459c Pashmak and Buses
E - Pashmak and Buses Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- cf 459E
cf459E 这题说的是 给定一个n点m条边的带边权的有向图,从中找出一条路径(可以带环),该路径包含的边数最多,并且要求路径中的权值必须严格递增,然后对边进行排序完个后采用dp去解特殊判断一下边权值 ...
- 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 ...
- codeforces 459E
codeforces 459E E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabyte ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
随机推荐
- VC++ 利用CreateFile、ReadFile和WriteFile实现CopyFile
1. CreateFile:这是一个多功能的函数,可打开或创建以下对象,并返回可访问的句柄:控制台,通信资源,目录(只读打开),磁盘驱动器,文件,邮槽,管道. 参照:http://www.cppblo ...
- Python3基础 函数 递归 阶乘与斐波那契数列
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- [shiro] - 怎样使用shiro?
shiro是什么? Shiro是apache旗下的一个开源框架, 它将软件系统的安全认证相关的功能抽取出来, 实现用户身份认证, 权限授权, 加密, 会话管理等功能, 组成一个通用的安全认证框架. 为 ...
- 函数递归简单题-hdoj-2044 2018-一只小蜜蜂 母牛的故事
题目:一只小蜜蜂 递归做法: #include<cstdio> #include<iostream> #include<stdlib.h> #include< ...
- 实现简单的ORM
介绍 本篇将介绍实现简单的ORM,即:对数据表的通用操作:增.删.改.查 数据访问层 数据访问层类图 类说明: 1.DbProvider(供应):为数据操作提供基本对象,如:连接.操作对象.事务... ...
- 使用rviz 查看远程主机
一.安装好ros环境 https://www.cnblogs.com/sea-stream/p/9809590.html 二.配置参数 vim ~/.bashrc #输入内容 export ROS_H ...
- Could NOT find SDL_image (missing:SDL_IMAGE_LIBRARIES SDL_IMAGE_INCLUDE_DIRS)
sudo apt-get install libsdl-image1.2-dev
- python 无序表查找
def sequential_search(lis, key): for i in range(len(lis)): if(lis[i] == key): return i else: return ...
- Jmeter 测试API接口 查看接口的幂等问题
背景介绍: 比如一个注册接口,要求填入的手机号与DB中已有的不能重复, 如果手机号码重复,则此次注册失败,不会新增会员数据: 如果不重复,则注册成功(忽略其他因素). 但是用20个并发,同样的请求,请 ...
- [ios]MKMapView中使用MKPolyline画线
参考:http://blog.sina.com.cn/s/blog_9e8867eb0101dt76.html 首先在MapView.h中 #import <MapKit/MapKit.h> ...