A

Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.

The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?

Input

The first line of the input contains three integers nb and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.

Output

Print one integer — the number of times Kolya will have to empty the waste section.

 #include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define il inline
#define re register
using namespace std;
int n,b,d,a[],c,ans;
int main(){
scanf("%d%d%d",&n,&b,&d);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]>b) continue;
c+=a[i];
if(c>d){
c=;ans++;
}
}
cout<<ans;
return ;
}

B

Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x1, x2, ..., xn. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary order.

Vasya wants to pick such checkpoints and the order of visiting them that the total distance travelled is minimized. He asks you to calculate this minimum possible value.

Input

The first line of the input contains two integers n and a (1 ≤ n ≤ 100 000,  - 1 000 000 ≤ a ≤ 1 000 000) — the number of checkpoints and Vasya's starting position respectively.

The second line contains n integers x1, x2, ..., xn ( - 1 000 000 ≤ xi ≤ 1 000 000) — coordinates of the checkpoints.

Output

Print one integer — the minimum distance Vasya has to travel in order to visit at least n - 1 checkpoint.

 #include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define il inline
#define re register
using namespace std;
int n,x,a[];
int main(){
scanf("%d%d",&n,&x);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
if(n==){
cout<<"";return ;
}
if(x<a[]){
cout<<abs(a[n-]-x);return ;
}
if(x>a[n]){
cout<<abs(a[]-x);return ;
}
if(n==){
cout<<min(abs(a[]-x),abs(a[n]-x));return ;
}
cout<<min(min(abs(x-a[]),abs(a[n]-x))+abs(a[]-a[n]),min(abs(x-a[]),abs(x-a[n-]))+abs(a[]-a[n-]));
return ;
}

C

You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z'  'y'  'x'  'b'  'a'  'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.

What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?

Input

The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.

Output

Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.

 #include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define il inline
#define re register
using namespace std;
char s[];
int n,a,b;
il bool chk(){
for(int i=;i<=n;i++)
if(s[i]!='a') return false;
return true;
}
int main(){
scanf("%s",s+);n=strlen(s+);
if(chk()){
for(int i=;i<n;i++)
printf("a");
cout<<'z';return ;
}
a=;
while(s[a]=='a') a++;
for(int i=;i<a;i++) printf("%c",s[i]);
for(int i=a;i<=n;i++){
if(s[i]!='a'){
printf("%c",s[i]-);
}
else{
for(int j=i;j<=n;j++)
printf("%c",s[j]);
return ;
}
}
return ;
}

D

For each string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 and a11, where axy is the number ofsubsequences of length 2 of the string s equal to the sequence {x, y}.

In these problem you are given four integers a00, a01, a10, a11 and have to find any non-empty string s that matches them, or determine that there is no such string. One can prove that if at least one answer exists, there exists an answer of length no more than1 000 000.

Input

The only line of the input contains four non-negative integers a00, a01, a10 and a11. Each of them doesn't exceed 10^9.

Output

If there exists a non-empty string that matches four integers from the input, print it in the only line of the output. Otherwise, print "Impossible". The length of your answer must not exceed 1 000 000.

这个嘛,预处理要多少个1和0,然后01和10加起来的数目是固定的,因此满足一个就好了。

 #include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define il inline
#define re register
using namespace std;
typedef long long ll;
ll n=-,a1,a2,a3,a4,s=-,t=-,a,p;
int main(){
cin>>a1>>a2>>a3>>a4;a=a1+a2+a3+a4;
for(ll i=;i<=;i++){
if(i*(i-)/==a){
n=i;break;
}
}
if(n==-){
cout<<"Impossible";return ;
}
if(a1==a){
for(int i=;i<=n;i++)
printf("");
return ;
}
if(a4==a){
for(int i=;i<=n;i++)
printf("");
return ;
}
for(ll i=;i<=;i++){
if(i*(i-)/==a1){
s=i;break;
}
}
for(ll i=;i<=;i++){
if(i*(i-)/==a4){
t=i;break;
}
}
if(s==-&&t==-){
cout<<"Impossible";return ;
}
if(a2+a3!=s*t){
cout<<"Impossible";return ;
}
p=a2/s+(a2%s>);
if(p>t){
cout<<"Impossible";return ;
}
for(int i=;i<=t-p;i++)
printf("");
for(int i=;i<=s;i++){
printf("");
if(a2%s==i){
printf("");
}
}
for(int i=;i<=a2/s;i++)
printf("");
return ;
}

E

Tree is a connected acyclic graph. Suppose you are given a tree consisting of n vertices. The vertex of this tree is called centroid if the size of each connected component that appears if this vertex is removed from the tree doesn't exceed .

You are given a tree of size n and can perform no more than one edge replacement. Edge replacement is the operation of removing one edge from the tree (without deleting incident vertices) and inserting one new edge (without adding new vertices) in such a way that the graph remains a tree. For each vertex you have to determine if it's possible to make it centroid by performing no more than one edge replacement.

Input

The first line of the input contains an integer n (2 ≤ n ≤ 400 000) — the number of vertices in the tree. Each of the next n - 1 lines contains a pair of vertex indices ui and vi (1 ≤ ui, vi ≤ n) — endpoints of the corresponding edge.

Output

Print n integers. The i-th of them should be equal to 1 if the i-th vertex can be made centroid by replacing no more than one edge, and should be equal to 0 otherwise.

如果有两个重心,则把重心边破开,把其中一边接到另外一边即可

如果有一个重心,则找到重心最大的一个子树,把它断开和当前点接上。

如果当前点在那个子树上,就和次大的接上。

 #include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define il inline
#define re register
using namespace std;
const int N=;
struct edge{int next,to;
} e[N];
int g[N],n,M,cn,c[],fir,sec,color[N],s[N];
il void addedge(int x,int y){
e[++M]=(edge){g[x],y};g[x]=M;
}
il void dfs1(int h,int fa){
bool flag=true;
for(int i=g[h];i;i=e[i].next){
if(e[i].to==fa) continue;
dfs1(e[i].to,h);
if(s[e[i].to]>n/) flag=false;
}
if(n-s[h]<=n/&&flag==true){
c[cn++]=h;
}
}
il void dfs2(int h,int fa){
s[h]=;
for(int i=g[h];i;i=e[i].next){
if(fa==e[i].to||e[i].to==c[]) continue;
dfs2(e[i].to,h);s[h]+=s[e[i].to];
}
}
il void dfs3(int h,int fa){
for(int i=g[h];i;i=e[i].next){
if(fa==e[i].to||e[i].to==c[]) continue;
color[e[i].to]=;dfs3(e[i].to,h);
}
}
il void predo(){
dfs2(,);
dfs1(,);
}
int main(){
scanf("%d",&n);
for(int i=,x,y;i<n;i++){
scanf("%d%d",&x,&y);
addedge(x,y);
addedge(y,x);
}
predo();
if(cn==){
for(int i=;i<=n;i++)
printf("1 ");
return ;
}
dfs2(c[],);
for(int j=g[c[]];j;j=e[j].next){
if(e[j].to==c[]||e[j].to==c[]) continue;
if(s[e[j].to]>s[fir]){
sec=fir;
fir=e[j].to;
}
else if(s[e[j].to]>s[sec]){
sec=e[j].to;
}
}
color[fir]=;dfs3(fir,);
for(int i=;i<=n;i++){
if(i==c[]){
printf("1 ");continue;
}
if(color[i]){
if(n-s[sec]-s[i]<=n/){
printf("1 ");
}
else printf("0 ");
}
else{
if(n-s[fir]-s[i]<=n/){
printf("1 ");
}
else{
printf("0 ");
}
}
}
return ;
}

Codeforces709的更多相关文章

随机推荐

  1. clean code(一)

    代码整洁之道对于程序的重构及可读性至关重要.开始整洁之道吧!!! 一.抽离try catch 模块 public void delete(Page page){ try { deletePageAnd ...

  2. pyquery详细用法

    python爬虫之PyQuery的基本使用   PyQuery库也是一个非常强大又灵活的网页解析库,如果你有前端开发经验的,都应该接触过jQuery,那么PyQuery就是你非常绝佳的选择,PyQue ...

  3. Elasticsearch.Net 异常:[match] query doesn't support multiple fields, found [field] and [query]

    用Elasticsearch.Net检索数据,报异常: )); ElasticLowLevelClient client = new ElasticLowLevelClient(settings); ...

  4. Laxcus大数据操作系统单机集群版

    Laxcus大数据管理系统是我们Laxcus大数据实验室历时5年,全体系全功能设计研发的大数据产品,目前的最新版本是2.1版本.从三年前的1.0版本开始,Laxcus大数据系统投入到多个大数据和云计算 ...

  5. oracle查询数据库所有用户信息

    看到网上说的查询用户的语句: SELECT * FROM dba_users;这句好像只能系统管理员才能成功执行,普通用户无法执行 SELECT count(*) FROM all_users; , ...

  6. 亚马逊中国耳机巨头Jabra官方旗舰店上线

    日前,亚马逊中国(Z.cn)宣布,全球无线技术顶级领导品牌 Jabra (捷波朗)官方旗舰店正式上线,产品品类涵盖蓝牙耳机.音乐耳机.无线音箱和车载系列产品.Jabra 旗舰店上线伊始便汇集了 60 ...

  7. 2.airflow参数简介

    比较重要的参数: 参数 默认值 说明 airflow_home /home/airflow/airflow01 airflow home,由环境变量$AIRFLOW_HOME决定 dags_folde ...

  8. Java课程实验报告 实验四 Java网络编程及安全

    北京电子科技学院(BESTI) 实     验    报     告 课程:Java程序设计     班级:1352     姓名:吕松鸿  学号:20135229 成绩:               ...

  9. 按Right-BICEP要求的对任务二的测试用例

    测试方法:Right-BICEP 测试计划 1.Right-结果是否正确? 2.B-是否所有的边界条件都是正确的? 3.P-是否满足性能要求? 4.是否有乘除法? 5.是否有括号? 6.是否有真分数? ...

  10. "感应锁屏"Alpha版使用说明

    “感应锁屏”Alpha版使用说明 一.产品介绍 感应锁屏是锁屏软件的一大创新.相比传统的锁屏软件,“感应锁屏”从可操作性.方便性.功能全面性都有了很大的提升,可以让用户方便快捷的进行锁屏操作. “感应 ...