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 ...
随机推荐
- Python3基础 json.loads 解析json格式的数据,得到一个字典
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- linux性能分析工具之火焰图
一.环境 1.1 jello@jello:~$ uname -a Linux jello 4.4.0-98-generic #121-Ubuntu SMP Tue Oct 10 14:24:03 UT ...
- C Looooops(扩展欧几里得)题解
A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != ...
- 【附5】springboot之配置文件
本文转载自http://www.jianshu.com/p/80621291373b,作者:龙白一梦 我的boss 代码从开发到测试要经过各种环境,开发环境,测试环境,demo环境,线上环境,各种环境 ...
- Codeforces Round #223 (Div. 2) E. Sereja and Brackets 线段树区间合并
题目链接:http://codeforces.com/contest/381/problem/E E. Sereja and Brackets time limit per test 1 secon ...
- ubuntu server 16.04(amd 64) 配置网桥,多网卡使用激活
安装了Ubuntu16.04的server版本,结果进入系统输入ifconfig后发现,只有一个网卡enp1s0,还有一个网络回路lo,ifconfig -a 发现其实一共有四个网卡,enp1s0,e ...
- shell模拟ctrl c停止
kill命令可以带信号号码选项,也可以不带. 如果没有信号号码,kill命令就会发出终止信号(15),这个信号可以被进程捕获,使得进程在退出之前可以清理并释放资源. 也可以用kill向进程发送特定的信 ...
- PHP 高精度比较bccomp
/** * 比较大小 */ public static function compareNum($num1,$num2) { return bccomp($num1,$num2,3); // 精确到小 ...
- BeautifulSoup中的select方法
在写css时,标签名不加任何修饰,类名前加点,id名前加 #,我们可以用类似的方法来筛选元素,用到的方法是soup.select(),返回类型是list. (1).通过标签名查找 print(soup ...
- 已使用 163 邮箱测试通过,且支持 SSL 连接。 发送邮件
示例:Jack 发送一封邮件给 Rose. public class SendMail { public static void main(String[] args) { b ...