手速场2333,这群人贼牛逼!手速贼快!
 
A. Wrong Subtraction
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:

  • if the last digit of the number is non-zero, she decreases the number by one;
  • if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit).

You are given an integer number nn. Tanya will subtract one from it kk times. Your task is to print the result after all kk subtractions.

It is guaranteed that the result will be positive integer number.

Input

The first line of the input contains two integer numbers nn and kk (2≤n≤1092≤n≤109, 1≤k≤501≤k≤50) — the number from which Tanya will subtract and the number of subtractions correspondingly.

Output

Print one integer number — the result of the decreasing nn by one kk times.

It is guaranteed that the result will be positive integer number.

Examples
input

Copy
512 4
output

Copy
50
input

Copy
1000000000 9
output

Copy
1

水题,不说。

 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define clrmax(x) memset(x,0x3f3f3f3f,sizeof(x))
#define mod 1000000007
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
#define ls(i) (i<<1)
#define rs(i) (i<<1|1)
#define mp make_pair
using namespace std;
LL n;
int k;
int main()
{
scanf("%I64d%d",&n,&k);
for(int i=;i<=k;i++)
{
if(n%==)
n/=;
else
n--;
}
printf("%I64d\n",n);
return ;
}
B. Two-gram
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.

You are given a string ss consisting of nn capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string ss = "BBAABBBA" the answer is two-gram "BB", which contained in ss three times. In other words, find any most frequent two-gram.

Note that occurrences of the two-gram can overlap with each other.

Input

The first line of the input contains integer number nn (2≤n≤1002≤n≤100) — the length of string ss. The second line of the input contains the string ss consisting of nn capital Latin letters.

Output

Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string ss as a substring (i.e. two consecutive characters of the string) maximal number of times.

Examples
input

Copy
7
ABACABA
output

Copy
AB
input

Copy
5
ZZZAA
output

Copy
ZZ

拿个string 和map 存一存就好了。

 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define clrmax(x) memset(x,0x3f3f3f3f,sizeof(x))
#define mod 1000000007
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
#define ls(i) (i<<1)
#define rs(i) (i<<1|1)
#define mp make_pair
using namespace std;
const int N=1e2+;
map<string,int> st;
string str,s;
int n,ans;
int main()
{
cin>>n;
cin>>s;
ios::sync_with_stdio(false);
for(int i=;i<n-;i++)
{
str="";
str+=s[i];
str+=s[i+];
st[str]++;
}
ans=;
for(auto p:st)
{
if(p.second>ans)
{
ans=p.second;
str=p.first;
}
}
cout<<str<<endl;
}
C. Less or Equal
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a sequence of integers of length nn and integer number kk. You should print any integer number xx in the range of [1;109][1;109](i.e. 1≤x≤1091≤x≤109) such that exactly kk elements of given sequence are less than or equal to xx.

Note that the sequence can contain equal elements.

If there is no such xx, print "-1" (without quotes).

Input

The first line of the input contains integer numbers nn and kk (1≤n≤2⋅1051≤n≤2⋅105, 0≤k≤n0≤k≤n). The second line of the input contains nninteger numbers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the sequence itself.

Output

Print any integer number xx from range [1;109][1;109] such that exactly kk elements of given sequence is less or equal to xx.

If there is no such xx, print "-1" (without quotes).

Examples
input

Copy
7 4
3 7 5 1 10 3 20
output

Copy
6
input

Copy
7 2
3 7 5 1 10 3 20
output

Copy

-1


如果有解就是排完序后第k个。特判k==0,当最小数为1的时候无解,否则为1。特判k>n无解。特判a[k]==a[k+1]的情况,这样也是无解的。

 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define clrmax(x) memset(x,0x3f3f3f3f,sizeof(x))
#define mod 1000000007
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
#define ls(i) (i<<1)
#define rs(i) (i<<1|1)
#define mp make_pair
using namespace std;
const int N=2e5+;
int a[N];
int n,m,k,t;
int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++)
scanf("%d",a+i);
sort(a+,a+n+);
if(k==)
{
if(a[]==)
printf("-1\n");
else
printf("1\n");
return ;
}
printf("%d\n",(k>n || (k<n && a[k]==a[k+]))?-:a[k]);
return ;
}
D. Divide by three, multiply by two
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp likes to play with numbers. He takes some integer number xx, writes it down on the board, and then performs with it n−1n−1operations of the two kinds:

  • divide the number xx by 33 (xx must be divisible by 33);
  • multiply the number xx by 22.

After each operation, Polycarp writes down the result on the board and replaces xx by the result. So there will be nn numbers on the board after all.

You are given a sequence of length nn — the numbers that Polycarp wrote down. This sequence is given in arbitrary order, i.e. the order of the sequence can mismatch the order of the numbers written on the board.

Your problem is to rearrange (reorder) elements of this sequence in such a way that it can match possible Polycarp's game in the order of the numbers written on the board. I.e. each next number will be exactly two times of the previous number or exactly one third of previous number.

It is guaranteed that the answer exists.

Input

The first line of the input contatins an integer number nn (2≤n≤1002≤n≤100) — the number of the elements in the sequence. The second line of the input contains nn integer numbers a1,a2,…,ana1,a2,…,an (1≤ai≤3⋅10181≤ai≤3⋅1018) — rearranged (reordered) sequence that Polycarp can wrote down on the board.

Output

Print nn integer numbers — rearranged (reordered) input sequence that can be the sequence that Polycarp could write down on the board.

It is guaranteed that the answer exists.

Examples
input

Copy
6
4 8 6 3 12 9
output

Copy
9 3 6 12 4 8 
input

Copy
4
42 28 84 126
output

Copy
126 42 84 28 
input

Copy
2
1000000000000000000 3000000000000000000
output

Copy
3000000000000000000 1000000000000000000 

我可能是代码最长的那个233333。
反正就暴力链嘛,找到一个链一个,然后找没有被链的那个当头输出就好了。

 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define clrmax(x) memset(x,0x3f3f3f3f,sizeof(x))
#define mod 1000000007
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
#define ls(i) (i<<1)
#define rs(i) (i<<1|1)
#define mp make_pair
using namespace std;
const int N=1e2+;
LL a[N];
int nexted[N];
int n,hd,vis[N];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%I64d",a+i);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(!vis[j] && a[j]%== && a[i]==a[j]/)
{
nexted[i]=j;
vis[j]=;
break;
}
else if(!vis[j] && a[i]%== && a[i]==a[j]*)
{
nexted[i]=j;
vis[j]=;
break;
}
for(int i=;i<=n;i++)
if(vis[i]==)
{
hd=i;
break;
}
for(int i=;i<=n;i++)
{
printf("%I64d ",a[hd]);
hd=nexted[hd];
}
printf("\n");
return ;
}

然后听说了排序新奇写法,就是把含3因数多的尽可能的往前排,在含3因数一样的情况下小的数排前面。这样因为保证有解,排序出来的结果就是答案。

学了下lambda表达式

#include<bits/stdc++.h>
using namespace std;
long long n,a[];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%I64d",a+i);
sort(a+,a+n+,[](long long a,long long b)
{
int cnt[]={,};
while(a%==) a/=,cnt[]++;
while(b%==) b/=,cnt[]++;
return cnt[]==cnt[]?a<b:cnt[]>cnt[];
});
for(int i=;i<=n;i++)
printf("%I64d%c",a[i]," \n"[i==n]);
return ;
}
E. Cyclic Components
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an undirected graph consisting of nn vertices and mm edges. Your task is to find the number of connected components which are cycles.

Here are some definitions of graph theory.

An undirected graph consists of two sets: set of nodes (called vertices) and set of edges. Each edge connects a pair of vertices. All edges are bidirectional (i.e. if a vertex aa is connected with a vertex bb, a vertex bb is also connected with a vertex aa). An edge can't connect vertex with itself, there is at most one edge between a pair of vertices.

Two vertices uu and vv belong to the same connected component if and only if there is at least one path along edges connecting uu and vv.

A connected component is a cycle if and only if its vertices can be reordered in such a way that:

  • the first vertex is connected with the second vertex by an edge,
  • the second vertex is connected with the third vertex by an edge,
  • ...
  • the last vertex is connected with the first vertex by an edge,
  • all the described edges of a cycle are distinct.

A cycle doesn't contain any other edges except described above. By definition any cycle contains three or more vertices.

There are 66 connected components, 22 of them are cycles: [7,10,16][7,10,16] and [5,11,9,15][5,11,9,15].

Input

The first line contains two integer numbers nn and mm (1≤n≤2⋅1051≤n≤2⋅105, 0≤m≤2⋅1050≤m≤2⋅105) — number of vertices and edges.

The following mm lines contains edges: edge ii is given as a pair of vertices vivi, uiui (1≤vi,ui≤n1≤vi,ui≤n, ui≠viui≠vi). There is no multiple edges in the given graph, i.e. for each pair (vi,uivi,ui) there no other pairs (vi,uivi,ui) and (ui,viui,vi) in the list of edges.

Output

Print one integer — the number of connected components which are also cycles.

Examples
input

Copy
5 4
1 2
3 4
5 4
3 5
output

Copy
1
input

Copy
17 15
1 8
1 12
5 11
11 9
9 15
15 5
4 13
3 13
4 3
10 16
7 10
16 7
14 3
14 4
17 6
output

Copy
2

对每个点都做个标记。每个点都dfs一下判断是不是形成一个圈,如果度>2的就可以直接return了。

 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define clrmax(x) memset(x,0x3f3f3f3f,sizeof(x))
#define mod 1000000007
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
#define ls(i) (i<<1)
#define rs(i) (i<<1|1)
#define mp make_pair
using namespace std;
const int N=2e5+;
struct edg
{
int next,to;
}edge[N<<];
int head[N],etot,vis[N],ct[N];
int n,m,u,v;
int ans;
void init()
{
clr_1(head);
clr(vis);
clr(ct);
etot=;
ans=;
return ;
}
void addedge(int u,int v)
{
edge[++etot]=(edg){head[u],v};
head[u]=etot;
return ;
}
bool dfs(int u,int hed,int fa,int dep)
{
vis[u]=;
if(ct[u]>)
return ;
int p;
for(int i=head[u];i!=-;i=edge[i].next)
{
p=edge[i].to;
if(p==fa)
continue;
if(vis[p] && p==hed)
{
if(dep>=)
return ;
else
return ;
}
if(!vis[p])
return dfs(p,hed,u,dep+);
}
return ;
}
int main()
{
scanf("%d%d",&n,&m);
init();
for(int i=;i<=m;i++)
{
scanf("%d%d",&u,&v);
addedge(u,v);
addedge(v,u);
ct[u]++;
ct[v]++;
}
for(int i=;i<=n;i++)
{
if(!vis[i])
if(dfs(i,i,i,))
ans++;
}
printf("%d\n",ans);
return ;
}
F. Consecutive Subsequence
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an integer array of length nn.

You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x,x+1,…,x+k−1][x,x+1,…,x+k−1] for some value xx and length kk.

Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5,3,1,2,4][5,3,1,2,4] the following arrays are subsequences: [3][3], [5,3,1,2,4][5,3,1,2,4], [5,1,4][5,1,4], but the array [1,3][1,3] is not.

Input

The first line of the input containing integer number nn (1≤n≤2⋅1051≤n≤2⋅105) — the length of the array. The second line of the input containing nn integer numbers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the array itself.

Output

On the first line print kk — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.

On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.

Examples
input

Copy
7
3 3 4 7 5 6 8
output

Copy
4
2 3 5 6
input

Copy
6
1 3 5 2 4 6
output

Copy
2
1 4
input

Copy
4
10 9 8 7
output

Copy
1
1
input

Copy
9
6 7 8 3 4 5 9 10 11
output

Copy
6
1 2 3 7 8 9

LIS的 O(n) 写法 加上离散化。拿上lower_bound去找离散化的数。这样就能解决了。不过map的离散化代码能更短点。

 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define clrmax(x) memset(x,0x3f3f3f3f,sizeof(x))
#define mod 1000000007
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
#define ls(i) (i<<1)
#define rs(i) (i<<1|1)
using namespace std;
const int N=2e5+;
int a[N],uni[N],n,m,now[N],pre[N],last,maxn,t,p,ans[N],num[N];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",a+i);
uni[i]=a[i];
}
sort(uni+,uni+n+);
m=unique(uni+,uni+n+)-uni-;
last=maxn=;
for(int i=;i<=n;i++)
{
t=lower_bound(uni+,uni+m+,a[i])-uni;
if(num[t]<)
{
now[t]=i;
num[t]=;
}
p=lower_bound(uni+,uni+m+,a[i]-)-uni;
if(p>m || uni[p]!=a[i]-)
continue;
if(num[t]<num[p]+)
{
now[t]=i;
num[t]=num[p]+;
pre[i]=now[p];
}
if(num[t]>maxn)
{
last=i;
maxn=num[t];
}
}
printf("%d\n",maxn);
for(int i=maxn;i>=;i--)
{
ans[i]=last;
last=pre[last];
}
for(int i=;i<=maxn;i++)
printf("%d ",ans[i]);
printf("\n");
return ;
}

Codeforces Round #479 (Div. 3)的更多相关文章

  1. Codeforces Round #479 (Div. 3) A. Wrong Subtraction

    题目网址:http://codeforces.com/contest/977/problem/A 题解:给你一个数n,进行k次变换,从末尾开始-1,512变成511,511变成510,510会把0消掉 ...

  2. Codeforces Round #479 (Div. 3) C. Less or Equal

    题目地址:http://codeforces.com/contest/977/problem/C 题解:给一串数组,是否找到一个数x,找到k个数字<=x,找到输出x,不能输出-1.例如第二组,要 ...

  3. Codeforces Round #479 (Div. 3) F. Consecutive Subsequence (简单dp)

    题目:https://codeforces.com/problemset/problem/977/F 题意:一个序列,求最长单调递增子序列,但是有一个要求是中间差值都是1 思路:dp,O(n)复杂度, ...

  4. Codeforces Round #479 (Div. 3)解题报告

    题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...

  5. Codeforces Round #479 (Div. 3) B. Two-gram

    原题代码:http://codeforces.com/contest/977/problem/B 题解:有n个字符组成的字符串,输出出现次数两个字符组合.例如第二组样例ZZ出现了两次. 方法:比较无脑 ...

  6. Codeforces Round #479 (Div. 3) 题解 977A 977B 977C 977D 977E 977F

    A. Wrong Subtraction 题目大意:   定义一种运算,让你去模拟 题解:   模拟 #include <iostream> #include <cstdio> ...

  7. Codeforces Round #479 (Div. 3)题解

    CF首次推出div3给我这种辣鸡做,当然得写份博客纪念下 A. Wrong Subtraction time limit per test 1 second memory limit per test ...

  8. E. Cyclic Components (DFS)(Codeforces Round #479 (Div. 3))

    #include <bits/stdc++.h> using namespace std; *1e5+; vector<int>p[maxn]; vector<int&g ...

  9. Codeforces Round #479 (Div. 3)解题代码

    A. Wrong Subtraction #include <bits/stdc++.h> using namespace std; int main() { int n,k; cin&g ...

随机推荐

  1. [NOIP2003]栈 题解(卡特兰数)

    [NOIP2003]栈 Description 宁宁考虑的是这样一个问题:一个操作数序列,从1,2,一直到n(图示为1到3的情况),栈A的深度大于n. 现在可以进行两种操作: 1.将一个数,从操作数序 ...

  2. Oracle笔记之序列(Sequence)

    Oracle中序列是一种数据对象,可以视为一个等差数列,我们自增就是一个遍历这个数列的过程,可以取当前值,也可以将当前值自加n后返回,Sequence与表没有太大的关系,有的时候如果表的主键是数值类型 ...

  3. Distance Gym - 102028I (思维)

    题目链接:https://cn.vjudge.net/problem/Gym-102028I 具体思路:首先我们选定左边界和右边界.然后每一次按照左边一个,第二次右边一个的规律往上就可以了 具体原因: ...

  4. php文件上传——php经典实例

     php文件上传——php经典实例 表单页 <html> <head> <title>文件上传</title> <meta charset='ut ...

  5. 使用linux下的C操作SQLLITE

    from: http://baike.so.com/doc/1529694.html 由于Linux下侧重使用命令,没有win的操作容易上手,所以在测试C操作SQLITE时会比较容易出现错误,给大家做 ...

  6. jplayer.js 与 video.js

    HTML5 - 两款基于JS的视频播放器 都是基于h5 video 标签,如果不支持则会自动转成flash,这里个人比较推荐使用jplayer; 1.video.js pc端有时候会与视频打交道,如果 ...

  7. ftp,nfs和samba的区别

    先从名字上进行理解: 1. FTP(文件传输协议) 2. NFS(网络文件系统) 3. samba 即smb(服务信息块)协议 1 其中FTP 是TCP/IP协议栈所提供的一种子协议,该子协议具体可以 ...

  8. [ python ] 全局和局部作用域变量的引用

    全局与局部变量的引用 (a)locals(b)globals 这里还需要在补充2个关键字一起比较学习,关键字:(c)nonlocal(d)global locals 和 globals locals: ...

  9. LightOJ 1323 Billiard Balls(找规律(蚂蚁爬木棍))

    题目链接:https://vjudge.net/contest/28079#problem/M 题目大意: 一个边界长为L宽为W的平面同时发射n个台球,运动K秒,台球碰到桌面及两(多)个台球相撞情况如 ...

  10. C++实践积累

    C++ STL vector 如何彻底清空一个vector? 实践证明,vector.clear()并不能把vector容量清空,只会让vector.size()变为零,依然很占内存.那如何让vect ...