SER2016 DIV1 B, K 题解
来源:互联网 发布:综漫 收集数据做主神 编辑:程序博客网 时间:2024/05/22 05:33
B: Base Sums
时间限制: 1 Sec 内存限制: 128 MB提交: 17 解决: 0
[提交][状态][讨论版]
题目描述
Given three values n, a, and b, find the smallest m>n such that the sum of the digits of m in base a is the same as the sum of digits of m in base b.
输入
Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. There will be a single line of input, with three integers, n (0≤n≤1016), a and b (2≤a<b≤36), all of which will be in base 10.
输出
Output a single integer, m, which is the smallest number greater than n such that the sum of its digits in base a is the same as the sum of its digits in base b. Output m in base 10.
样例输入
66 10 16
样例输出
144
123
K: Zigzag
时间限制: 1 Sec 内存限制: 512 MB提交: 85 解决: 21
[提交][状态][讨论版]
题目描述
A sequence of integers is said to Zigzag if adjacent elements alternate between strictly increasing and strictly decreasing. Note that the sequence may start by either increasing or decreasing. Given a sequence of integers, determine the length of the longest subsequence that Zigzags. For example, consider this sequence:
1 2 3 4 2
There are several Zigzagging subsequences of length 3:
1 3 2 1 4 2 2 3 2 2 4 2 3 4 2
But there are none of length greater than 3, so the answer is 3.
1 2 3 4 2
There are several Zigzagging subsequences of length 3:
1 3 2 1 4 2 2 3 2 2 4 2 3 4 2
But there are none of length greater than 3, so the answer is 3.
输入
Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. The first line of input contains an integer n (1≤n≤1,000,000) which is the number of integers in the list. Each of the following n lines will have an integer k (1≤k≤1,000,000)
输出
Output a single integer, which is the length of the longest Zigzagging subsequence of the input list.
样例输入
5
1
2
3
4
2
样例输出
3
去重后 找 两端点 间的 拐点;
注意:
全部相同 答案为1; 一个端点
只有一个上升 或者 下降 答案为2 两个端点
#include <iostream>#include <stdio.h>#include <algorithm>#include <cmath>#include <cstring>#include <string>#include <queue>#include <stack>#include <stdlib.h>#include <list>#include <map>#include <set>#include <bitset>#include <vector>#define mem(a,b) memset(a,b,sizeof(a))#define findx(x) lower_bound(b+1,b+1+bn,x)-b#define FIN freopen("input.txt","r",stdin)#define FOUT freopen("output.txt","w",stdout)#define S1(n) scanf("%d",&n)#define SL1(n) scanf("%I64d",&n)#define S2(n,m) scanf("%d%d",&n,&m)#define SL2(n,m) scanf("%I64d%I64d",&n,&m)#define Pr(n) printf("%d\n",n) using namespace std;typedef long long ll;const double PI=acos(-1);const int INF=0x3f3f3f3f;const double esp=1e-6;const int maxn=1e7+5;const int MOD=1e9+7;const int mod=1e9+7;int dir[5][2]={0,1,0,-1,1,0,-1,0}; ll inv[maxn*2],fac[maxn];ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll ans=exgcd(b,a%b,x,y);ll temp=x;x=y;y=temp-a/b*y;return ans;}ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}void INV(){inv[1] = 1;for(int i = 2; i < maxn; i++) inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;}void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){ x=1; y=0; d=a; }else{ ex_gcd(b,a%b,d,y,x); y-=x*(a/b);}}void Fac(){fac[0]=1;for(int i=1;i<=maxn;i++)fac[i]=(fac[i-1]*i)%MOD;}ll inv_exgcd(ll a,ll n){ll d,x,y;ex_gcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}ll inv1(ll b){return b==1?1:(MOD-MOD/b)*inv1(MOD%b)%MOD;}ll inv2(ll b){return qpow(b,MOD-2);}ll cal(ll m,ll n){if(m<n)return 0;return (fac[m]*inv[fac[n]]%MOD)%MOD*inv[fac[m-n]]%MOD;}ll cals(ll m,ll n){if(m<n)return 0;return (fac[m]*inv1(fac[n])%MOD)%MOD*inv1(fac[m-n])%MOD;} int a[maxn];int main(){ int n; while(~scanf("%d",&n)){ mem(a,0); int t,k=1; scanf("%d",&a[1]); for(int i=2;i<=n;i++){ scanf("%d",&t); if(t!=a[k]) a[++k]=t; } if(k<2){ printf("1\n"); continue; } else{ int sum=2; for(int i=2;i<k;i++){ if(((a[i]>a[i-1])&&(a[i]>a[i+1]))||((a[i]<a[i-1])&&(a[i]<a[i+1]))){ sum++; } } // if(sum>2) printf("%d\n",sum); // else // printf("0\n"); } } return 0;}
阅读全文
0 0
- SER2016 DIV1 B, K 题解
- SER2016 DIV1(Paint)
- SER2016 DIV1 问题 H: Paint(区间问题贪心+dp优化)
- SRM 507 DIV1 B
- SRM 500 DIV1 B
- codeforces134 div1 B
- round 172Div1 B
- codeforces 228(div1) B
- codeforces-div1-286-B
- CodeForces 177(div1)B
- 【codeforces #275(div1)】AB题解
- [Codeforces #296 div1]简要题解
- Codeforces #302 Div1 简要题解
- TopCoder SRM484 div1 250 题解
- cf 80 div1 B(graph)
- codeforces round 176Div1 B
- Topcoder SRM 636 Div1 B
- Codeforces Round #219div1 部分题解
- 2017.9.3
- [BZOJ]5000: OI树 倍增
- 179.LK's problem
- 指针和数组与sizeof运算符(嵌入式笔试必考题)
- 面试技巧,如何通过索引说数据库优化能力,内容来自Java web轻量级开发面试教程
- SER2016 DIV1 B, K 题解
- Java IO : 流,以及装饰器模式在其上的运用
- HDU
- JS函数与获取本地时间与倒计时
- Singing-Voice Separation from Monaural Recordings using Deep Recurrent Neural Networks论文笔记
- EasyUI之data-options
- 文本域,支持多文本输入
- 关于如何将windows上代码上传至github中
- 线性回归、梯度下降、逻辑回归(Linear Regression、Gradient Descent、Logistic Regression)