Codeforces_831
A.线性判断。
#include<bits/stdc++.h>
using namespace std; int n,a[] = {}; int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i];
int t = ;
while(a[t] > a[t-]) t++;
while(a[t] == a[t-]) t++;
while(a[t] < a[t-]) t++;
if(t > n) cout << "YES" << endl;
else cout << "NO" << endl;
return ;
}
B.map转换一下。
#include<bits/stdc++.h>
using namespace std; map<char,char> mp;
string s,s1,s2;
int main()
{
ios::sync_with_stdio();
cin >> s1 >> s2 >> s;
for(int i = ;i < ;i++)
{
mp[s1[i]] = s2[i];
mp[s1[i]+'A'-'a'] = s2[i]+'A'-'a';
}
for(int i = ;i < s.length();i++)
{
if(mp.count(s[i])) cout << mp[s[i]];
else cout << s[i];
}
cout << endl;
return ;
}
C.先求评委前缀和,若要某方案符合,则必须所有n个点在k个评委的评分间隔内,枚举每个评委,对应一个点,判断是否符合要求即可,注意重复的情况。
#include<bits/stdc++.h>
using namespace std; int n,k,a[],b[];
map<int,int> mp,ok; int main()
{
ios::sync_with_stdio();
cin >> k >> n;
for(int i = ;i <= k;i++) cin >> a[i];
for(int i = ;i <= k;i++) a[i] += a[i-];
for(int i = ;i <= k;i++) mp[a[i]] = ;
for(int i = ;i <= n;i++) cin >> b[i];
for(int i = n;i >= ;i--) b[i] -= b[];
int ans = ;
for(int i = ;i <= k;i++)
{
int flag = ;
for(int j = ;j <= n;j++)
{
if(!mp.count(a[i]+b[j]))
{
flag = ;
break;
}
}
if(flag && !ok.count(a[i]))
{
ans++;
ok[a[i]] = ;
}
}
cout << ans << endl;
return ;
}
D.先对人和钥匙排序,最优的结果肯定是人在钥匙中连续的某一段,暴力枚举每一段就可以了。
#include<bits/stdc++.h>
using namespace std; int n,k,p,a[],b[]; int main()
{
ios::sync_with_stdio();
cin >> n >> k >> p;
for(int i = ;i <= n;i++) cin >> a[i];
for(int i = ;i <= k;i++) cin >> b[i];
sort(a+,a++n);
sort(b+,b++k);
int ans = INT_MAX;
for(int i = ;i+n- <= k;i++)
{
int maxx = ;
for(int j = ;j <= n;j++)
{
int t = i+j-;
maxx = max(maxx,abs(a[j]-b[t])+abs(b[t]-p));
}
ans = min(ans,maxx);
}
cout << ans << endl;
return ;
}
E.给每个数字开个set,储存每个数字下标,原数组排序一下,从小到大开始操作,用树状数组计数。
#include<bits/stdc++.h>
using namespace std; int n,a[],tree[] = {};
set<int> s[]; inline int lowbit(int x)
{
return x&-x;
} void update(int pos,int x)
{
while(pos <= n)
{
tree[pos] += x;
pos += lowbit(pos);
}
} int getsum(int pos)
{
int sum = ;
while(pos > )
{
sum += tree[pos];
pos -= lowbit(pos);
}
return sum;
} int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++)
{
cin >> a[i];
s[a[i]].insert(i);
update(i,);
}
sort(a+,a++n);
int now = ;
long long ans = ;
for(int i = ;i <= n;i++)
{
int t = a[i];
auto it = s[t].lower_bound(now);
if(it == s[t].end())
{
ans += getsum(n)-getsum(now);
it = s[t].lower_bound();
now = ;
}
ans += getsum(*it)-getsum(now);
now = *it;
update(*it,-);
s[t].erase(it);
}
cout << ans << endl;
return ;
}
F.要求最大的d,使得 

枚举每一个可能的
中d的值,对每一个可能的值计算d再判断。
#include<bits/stdc++.h>
using namespace std; long long n,k,a[],b[]; int main()
{
ios::sync_with_stdio();
cin >> n >> k;
int cnt = ;
long long sum = k;
for(int i = ;i <= n;i++)
{
cin >> a[i];
sum += a[i];
for(int j = ;j*j <= a[i];j++)
{
b[++cnt] = j;
b[++cnt] = (a[i]+j-)/j;
}
}
sort(b+,b++cnt);
cnt = unique(b,b++cnt)-b-;
long long ans = ;
for(int i = ;i <= cnt;i++)
{
long long now = ;
for(int j = ;j <= n;j++) now += (a[j]+b[i]-)/b[i];
if(sum/now >= b[i]) ans = max(ans,sum/now);
}
cout << ans << endl;
return ;
}
Codeforces_831的更多相关文章
随机推荐
- 1047 编程团体赛 (20 分)C语言
编程团体赛的规则为:每个参赛队由若干队员组成:所有队员独立比赛:参赛队的成绩为所有队员的成绩和:成绩最高的队获胜. 现给定所有队员的比赛成绩,请你编写程序找出冠军队. 输入格式: 输入第一行给出一个正 ...
- 为什么TCP建立连接协议是三次握手,而关闭连接却是四次握手呢?
看到了一道面试题:"为什么TCP建立连接协议是三次握手,而关闭连接却是四次握手呢?为什么不能用两次握手进行连接?",想想最近也到金三银四了,所以就查阅了相关资料,整理出来了这篇文章 ...
- 6.6 hadoop作业调优
提高速度和性能.可以从下面几个点去优化 可以在本地运行调试来优化性能,但是本地和集群是完全不同的环境,数据流模式也截然不同,性能优化要在集群上测试.有些问题如(内存溢出)只能在集群上重现. HPROF ...
- 论Java中的抽象类与接口
目录 抽象类和抽象方法 定义 与普通类的区别以及注意点: 抽象类的作用 接口 定义 示例 注意 作用 最后:接口与抽象类的异同 使用场景 借鉴 抽象类和抽象方法 定义 抽象方法和抽象类都必须被abst ...
- eclipse maven工程错误总汇
1.问题: Target runtime Apache Tomcat v7.0 is not defined 解决方法: right click on your project & ...
- python 条件判断的三元表达式
示例:求两数中最大者 在JavaScript中代码如下: x = 1; y = 2; console.log(x > y ? x : y) 在python中代码如下: # 条件为真时的返回结果 ...
- SVN打patch,某Java文件提示svn:mime-type = application/octet-stream的问题
在使用SVN合版本时发现某文件有冲突,正常冲突文件是可以编辑修改的,但是该文件无法编辑,我只好选择后续修改选项,问题好诡异啊!!!在解决完其他冲突后,我选择了在eclipse开发工具内将修改的代码调整 ...
- 【译】如何使用Vue过渡效果来提升用户体验
在Vue应用中添加过渡效果是一个可以使你的项目感觉更专业的简单方法.通过提升用户体验,可以使你的网站留住更多的用户以及提高转化率. 只需要简单的处理就可以获得巨大的回报,何乐而不为? 在这个指南中,我 ...
- JAVA中常用的异常处理方法
1.在Java项目中经常遇到的异常情况 算术异常类:ArithmeticExecption 空指针异常类:NullPointerException 类型强制转换异常:ClassCastExceptio ...
- redis 支持事务
pipe = conn.pipeline(transaction=True) pipe.multi() pipe.set(') pipe.hset('k3','n1',666) pipe.lpush( ...