Codeforces_714
A.相遇时间段l = max(l1,l2),r = min(r1,r2),再判断k是否在里面。
#include <iostream>
using namespace std; long long l1,l2,r1,r2,k; int main()
{
cin >> l1 >> r1 >> l2 >> r2 >> k;
long long l = max(l1,l2),r = min(r1,r2);
if(l > r) cout << << endl;
else
{
long long t = r-l+;
if(l <= k && k <= r) t--;
cout << t << endl;
}
return ;
}
B.判断出现的数的个数,1或2个直接YES,3个以上直接NO,3个判断是否等差。
#include<bits/stdc++.h>
using namespace std; int n,a[];
map<int,int> mp; int main()
{
ios::sync_with_stdio(false);
cin >> n;
int cnt = ;
for(int i = ;i <= n;i++)
{
int x;
cin >> x;
if(!mp.count(x))
{
cnt++;
mp[x] = ;
a[cnt] = x;
}
}
if(cnt == || cnt == ) cout << "YES" << endl;
else if(cnt >= ) cout << "NO" << endl;
else
{
sort(a+,a+);
if(a[]+a[] == *a[]) cout << "YES" << endl;
else cout << "NO" << endl;
}
return ;
}
C.把每一个数都转换成18位的pattern串,放进map处理。
#include<bits/stdc++.h>
using namespace std; int n;
map<string,int> mp; int main()
{
ios::sync_with_stdio(false);
cin >> n;
while(n--)
{
string s1,s2,s = "";
cin >> s1 >> s2;
for(int i = s2.length()-;i >= ;i--)
{
if((s2[i]-'')%) s = ""+s;
else s = ""+s;
}
while(s.length() < ) s = ""+s;
if(s1 == "+") mp[s]++;
else if(s1 == "-") mp[s]--;
else cout << mp[s] << endl;
}
return ;
}
D.先把图分成左右或上下两块,然后二分每一块中矩形的四条边。
#include<bits/stdc++.h>
using namespace std; int n;
struct xx
{
long long x1,x2,y1,y2;
void print()
{
cout << x1 << " " << y1 << " " << x2 << " " << y2 << " ";
}
}; int query(int x1,int y1,int x2,int y2)
{
if(x1 > x2)swap(x1,x2);
if(y1 > y2)swap(y1,y2);
cout<<"? "<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
int ans;
cin>>ans;
return ans;
} xx f(int x1,int y1,int x2,int y2)
{
xx ans;
long long l = x1,r = x2;
while(l < r)
{
int mid = (l+r)/;
if(query(x1,y1,mid,y2) < ) l = mid+;
else r = mid;
}
ans.x2 = l;
l = x1,r = x2;
while(l < r)
{
int mid = (l+r+)/;
if(query(mid,y1,x2,y2) < ) r = mid-;
else l = mid;
}
ans.x1 = l;
l = y1,r = y2;
while(l < r)
{
int mid = (l+r)/;
if(query(x1,y1,x2,mid) < ) l = mid+;
else r = mid;
}
ans.y2 = l;
l = y1,r = y2;
while(l < r)
{
int mid = (l+r+)/;
if(query(x1,mid,x2,y2) < ) r = mid-;
else l = mid;
}
ans.y1 = l;
return ans;
}
int main()
{
cin >> n;
long long x1,y1,x2,y2,x3,y3,x4,y4;
long long l = ,r = n;
while(l < r)
{
long long mid = (l+r)/;
if(query(,,mid,n) < ) l = mid+;
else r = mid;
}
long long t = l;
if(query(,,t,n) == && query(t+,,n,n) == )
{
xx a = f(,,t,n),b = f(t+,,n,n);
cout << "! ";
a.print();
b.print();
cout << endl;
return ;
}
l = ,r = n;
while(l < r)
{
long long mid = (l+r)/;
if(query(,,n,mid) < ) l = mid+;
else r = mid;
}
t = l;
xx a = f(,,n,t),b = f(,t+,n,n);
cout << "! ";
a.print();
b.print();
cout << endl;
return ;
}
E.如果是非严格单调递增该如何做,我们会发现每次调整,都是调整某个数字为原先数列中存在的数字,最后才是最优的,所以,我们设DP[i][j]表示前i个数字,最后一个数为原先数列排序后第j大的数字的最小代价,然后令a[i]=a[i]-i,把严格单调递增就转化为非严格单调递增。
#include<bits/stdc++.h>
using namespace std; int n;
long long a[],b[],dp[][]; int main()
{
cin >> n;
for(int i = ;i <= n;i++)
{
cin >> a[i];
a[i] -= i;
b[i] = a[i];
}
sort(b+,b++n);
for(int i = ;i <= n;i++)
{
long long minn = dp[i-][];
for(int j = ;j <= n;j++)
{
minn = min(minn,dp[i-][j]);
dp[i][j] = abs(a[i]-b[j])+minn;
}
}
long long ans = dp[n][];
for(int i = ;i <= n;i++) ans = min(ans,dp[n][i]);
cout << ans << endl;
return ;
}
还有优先队列优化的。
#include<bits/stdc++.h>
using namespace std; int n;
priority_queue<long long> q; int main()
{
cin >> n;
long long ans = ;
for(int i = ;i <= n;i++)
{
long long x;
cin >> x;
x -= i;
q.push(x);
if(q.top() > x)
{
ans += q.top()-x;
q.pop();
q.push(x);
}
}
cout << ans << endl;
return ;
}
Codeforces_714的更多相关文章
随机推荐
- 无聊读论文:视觉注意力模型RARE2012
Riche, N., Mancas, M., Duvinage, M., Mibulumukini, M., Gosselin, B., & Dutoit, T. (2013). RARE20 ...
- 性能数据的准备-Jmeter
性能测试的一般流程: 收集性能需求——>编写性能脚本——>执行性能测试——>分析测试报告——>系统性能调优 在收集性能需求后,我们会思考: 负载测试时并发时需要多少数据?例:登 ...
- Cannot access org.springframework.context.ConfigurableApplicationContext
Cannot access org.springframework.context.ConfigurableApplicationContext 需要将有问题的模块 删除 后重新导入 即可 IDEA ...
- Go Web 编程之 程序结构
概述 一个典型的 Go Web 程序结构如下,摘自<Go Web 编程>: 客户端发送请求: 服务器中的多路复用器收到请求: 多路复用器根据请求的 URL 找到注册的处理器,将请求交由处理 ...
- 悄摸直播(二)—— 播流器实现(拉取rtmp服务器中的数据流,播放直播画面)
悄摸直播 -- JavaCV实现本机摄像头画面远程直播 播流器 一.功能说明 从rtmp服务器中获取视频流数据 + 展示直播画面 二.代码实现 /** * 播流器 * @param inputPath ...
- floj 2265 【lxs Contest #141】航海舰队
首先抠出包围了阵形的最小矩形. 将地图拉伸成一条链,即将第一行.第二行.第三行按顺序连接.阵形也可以用同样的方法处理. 那么问题转化为,给定两个 01 串 S 和 T,问每个 S 中长度为 |T| 的 ...
- Android学习进度一
在解决了电脑产生的一系列问题之后成功安装了Android Studio,并在其自带的手机模拟器上成功运行了第一个App(Hello World!),通过这个最简单的App研究了App基本的工程结构,为 ...
- 网络流入门题目 - bzoj 1001
现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形: 左上角点 ...
- springboot下Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
已检查jar包是否引入 <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId ...
- Codeforces Round #615 (Div. 3)
A. Collecting Coins 题目链接:https://codeforces.com/contest/1294/problem/A 题意: 你有三个姐妹她们分别有 a , b , c枚硬币, ...