week15面向t1/t2的题们

A-Q老师的记录册

Problem Statement
Q 老师有 N 个学生,每个学生都有各自独立的编号,且编号范围在 1 ~ N 之间。
这一天,所有学生都在不同的时间进入教室。
Q 老师记录了当编号为 i 的学生进入教室时,教室中共有 Ai 个学生(包括编号为 i 的学生)。
现要求根据这些记录,给出学生进入教室的顺序。Constraints1 ≤ N ≤ 1e5
1 ≤ Ai ≤ N,Ai 各不相同
所有数字均为整数
Input
输入格式如下:
N
A1 A2 … AN
Output
根据学生进入教室的顺序输出学生的编号。
Sample Input 1

3
2 3 1

Sample Output 1
3 1 2
Sample Input 2

5
1 2 3 4 5

Sample Output 2
1 2 3 4 5
Sample Input 3

8
8 2 7 3 4 5 6 1

Sample Output 3
8 2 4 5 6 7 3 1

Codes

#include<iostream>
using namespace std;
const int maxn = 1e5 + 10;
int n, t,a[maxn];
int main(){
    while(cin>>n){
        for(int i = 1; i <= n;i++){
            cin >> t;
            a[t] = i;
        }
        for(int i = 1; i <= n;i++){
            cout << a[i];
            if(i<n)
                cout << " ";
        }
        cout << endl;
    }
    return 0;
}

B-ZJM的本领

众所周知,ZJM 住在 B 站。
这一天 Q 老师来找 ZJM 玩,ZJM 决定向 Q 老师展现一下自己快速看番的本领。
ZJM 让 Q 老师任意挑选了一部番,Q老师一眼看中了《辉夜大小姐想让我告白》,已知这部番一共有 N 个精彩片段,每个精彩片段用 [L[i], R[i]] 来表示。
ZJM 从第一分钟开始看,每次可以按下快进键,快进 X 分钟,问 ZJM 最快需要多久可以看完这部番。
Input
第一行给出两个整数 N、X(1 ≤ N ≤ 50, 1 ≤ X ≤ 1e5)
接下来 N 行,每行给出两个整数,L[i]、R[i](1 ≤ L[i] ≤ R[i] ≤ 1e5)
数据保证,R[i-1] < L[i]
Output
输出一个整数,表示 ZJM 最快看完这部番的时间。
**Examples **

INPUT
2 3
5 6
10 12
Output
  6
 
Input   
1 1
1 100000
Output
100000

Note
在第一个样例中,ZJM 从第 1 分钟开始看,由于 [1, 3] 区间内没有精彩片段,因此 ZJM 快进到了第 4 分钟。
观看完 [4, 6] 区间的内容后,时间来到了第 7 分钟,由于 [7, 9] 区间内没有精彩片段,因此 ZJM 快进到了第 10 分钟,观看完 [10, 12] 区间的内容后,看番结束。
一共耗时 3 + 3 = 6 分钟。

Codes

#include<iostream>
using namespace std;
const int maxn = 1e5 + 10;
int n, x;
struct fan{
    int l, r;
}f[maxn];
int main(){
    while(cin>>n>>x){
        int ans = 0,tot;
        f[0].r = f[0].l = 1;
        for (int i = 1; i <= n;i++){
            cin >> f[i].l >> f[i].r;
            if(i==1)
                tot = f[i].l - f[i - 1].r;
            else
               tot = f[i].l - f[i - 1].r - 1;
            ans += 1 + tot % x + f[i].r - f[i].l;
        }
        cout << ans << endl;
    }
    return 0;
}

C-TT的神秘任务

TT 的神秘任务系列。
这一次,TT 得到了一个长度为 N 的字符串,任务要求在原字符串中至多删去一个字符,使得字符串的字典序尽可能小。
字符串字典序的比较优先级如下:

从左往右第一个不同字符的 ASCII 值的大小关系
字符串长度
Input
第一行给出 N(2 ≤ N ≤ 2e5)。
第二行给出一个长度为 N,且仅包含小写字母的字符串。
Output
输出字典序最小的字符串。
Examples

Input  
3
aaa
Output
aa

Input   
5
abcda
Output
abca

Codes

#include<iostream>
using namespace std;
const int maxn = 2 * 1e5 + 10;
char ch[maxn];
int n;
int main(){
    while(cin>>n){
        int tag=-1,flag=0;
        for (int i = 0; i < n;i++)
            cin >> ch[i];
        for (int i = 0; i < n;i++){
            if(i<n && ch[i]>ch[i+1]){
                tag = i;
                break;
            }
        }
        if(tag==-1){
            for (int i = 0; i < n-1;i++){
                if(ch[i]!=ch[i+1]){
                    flag = 1;
                    break;
                }  
            }
            if(flag==0)
                tag = 0;
            else if(flag==1)
                tag = n - 1;
        }
        for (int i = 0; i < n;i++)
            if(i!=tag)
                cout << ch[i];
        cout << endl;
    }
    return 0;
}

D-瑞瑞爱上字符串

瑞瑞最近迷上了字符串,因此决定出一个字符串的题。
给定两个正整数 N、K,考虑所有由 N - 2 个 a 和 2 个 b 组成的字符串,要求输出其中字典序第 K 小的。
例如当 N = 5 时,共有如下 10 种组成方式:


aaabb
aabab
aabba
abaab
ababa
abbaa
baaab
baaba
babaa
bbaaa


Input
多组数据,第一行给定 T,表示数据组数。(1 ≤ T ≤ 1e4)
对于每组数据,给出两个正整数 N、K。(3 ≤ N ≤ 1e5, 1 ≤ K ≤ min(2e9, N * (N-1) / 2 ))
N 的总和不会超过 1e5。
Output
对于每组数据,输出长度为 N 的字典序第 K 小的字符串。
Example

Input
7
5 1
5 2
5 8
5 10
3 1
3 2
20 100 
Output
aaabb
aabab
baaba
bbaaa
abb
bab
aaaaabaaaaabaaaaaaaa

Codes

#include<iostream>
using namespace std;
int main(){
	int n,k,t;
	cin>>t;
	while(t--){
		cin>>n>>k;
		int a=0,sum=0,tmp=-1,b1,b2;
		while(k>=sum){
			a++;sum+=a;
		}
		sum-=a;
		if(k==sum){
			a--;tmp=a--;
		}
		else{
			while(k-sum){
				tmp++;sum++;
			}
		}
		b1=n-tmp;b2=n-a;
		for(int i=1;i<=n;i++){
			if(i==b1 || i==b2) cout<<"b";
			else cout<<"a";
		}
		cout<<endl;
	}
	return 0;
}

E - 苟狗之宇宙射线再打击

苟狗定义了一种新式字符串,只有掌握了这种字符串的构造方法,才可以避免宇宙射线的打击。
新式字符串定义如下:

长度为偶数(可以为空)
每一个奇数位置的字符都不等于它后面的那个字符

例如,字符串 good、string、xyyx 都符合要求,而字符串 bad、aa、aabc 则不符合。
现在你获得了一个字符串 S,你需要从该字符串中删除最少的字符数,使其变成一个新式字符串,否则你就会受到宇宙射线的打击,众所周知宇宙射线是降智射线。
那么你能够避开宇宙射线吗?
Input
一个行给定一个整数 N(1 <= N <= 200000),表示字符串 S 的长度。
第二行给定长度为 N 且仅包含小写字母的字符串 S。
Output
第一行输出一个数 K(0 <= K <= N),表示需要从 S 中删除的最少的字符数量。
第二行输出删除后的字符串 S。如果为空,你可以输出一个空字符串或者什么都不输出。
Examples

Input  
4
good
Output  
0
good

Input 
4
aabc
Output  
2
ab
Input 
3
aaa
Output 
3

Codes

#include<iostream>
using namespace std;
const int maxn=2*1e5+10;
int n;
char ch[maxn],a[maxn];
int main(){
	while(cin>>n){
		int kep=0,l=1,tot=0;
		for(int i=1;i<=n;i++)
			cin>>ch[i];
		while(l<n){
			if(ch[l]==ch[l+1])
				l++;
			else{
				a[tot]=ch[l];tot++;
				a[tot]=ch[l+1];tot++;
				kep+=2;
				l+=2;
			}
		}
		cout<<n-kep<<endl;
		for(int i=0;i<tot;i++)
			cout<<a[i];
		cout<<endl;
	}
	return 0;
}

F- 东东:“来不及解释了,快上车!!”

东东要上学了!
东东要去他家路口的公交车站等车!!!
东东从家出发,需要 d 分钟到达公交站台。
已知有 n 班公交车,第 i 路公交车在 a_i 分钟到达公交站台,随后每 b_i 分钟会有该路公交车。
东东想着他要迟到了!!!可恶!!!要迟到了!!于是他看见了一辆公交车来了,立马跳上了这辆"他见到的"第一辆公交车。
东东上车后发现了一个问题!!这不是去幼儿园的车!!!!可惜车门已经焊死。
那么问题来了东东上的是第几路车?
Input
第一行输入路线数n和东东到达的时间d(1≤n≤100,1≤d≤1e5)

接下来n行,每行两个数字a_i和b_i(1≤a_i,b_i≤1e5),分别为该路公交首辆车到达的时间和两辆车之间的发车间隔

如果有多种可能,输出一种
Output
东东所上车的公交车的路线编号。
Examples

Input
2 2
6 4
9 5
Output
1

Input
5 5
3 3
2 5
5 6
4 9
6 1
Output
3

Input
3 7
2 2
2 3
2 4
Output 
1

Codes

#include<iostream>
#include<algorithm>
using namespace std;
int n,d;
struct car{
	int sno,a,b;
	bool operator<(const car &ca) const{
		return ca.a!=a ? a<ca.a : b<ca.b;
	}
}c[220];
int main(){
	cin>>n>>d;
	for(int i=1;i<=n;i++){
		cin>>c[i].a>>c[i].b;
		c[i].sno=i;
	}
	sort(c+1,c+n+1);
	int x,f[110],it,ans;//f[i]是等待的时间 
	for(int i=1;i<=n;i++){
		x=c[i].a;
		if(x<d){
			while(x<d) x+=c[i].b;
			f[i]=x-d;
		}
		else if(x==d) f[i]=0;
		else f[i]=c[i].a-d;
	}
	ans=c[1].sno;
	for(int i=2;i<=n;i++){
		if(f[i]<f[i-1]) ans=c[i].sno;
		else f[i]=f[i-1];
	}
	cout<<ans<<endl;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值