# 19级爪哇程序设计新手赛2.0(参考题解)

## 看完它

A - Candies CodeForces - 1343A

（1）玄学观察法，咋们先来看看案例：

3			--》	1				除以3==2^2-1
6			--》	2				除以3
7			--》	1				除以7==2^3-1
21			--》	7				除以3
28			--》	4				除以7
999999999	--》	333333333		除以3
999999984	--》	333333328		除以3


（2）正规法：根据等比数列求和公式S=(a1-an*q)/(1-q)

#include <bits/stdc++.h>
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define db printf("where!\n");
#define pb push_back
using namespace std;
#define ll long long
ll gcd(ll x,ll y){return y ? gcd(y,x%y) : x;}
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}

int main()
{
while(t--){
for(int i=2;i<=n;i++){
ll a=pow(2,i)-1;
if(n%a==0){
cout<<n/a<<endl;
break;
}
}
}
return 0;
}


B - Balanced Array CodeForces - 1343B

n/2若为偶数，模拟如下

8

YES
2 4 6 8 1 3 5 11

2 4 6 8
1 3 5 8+(1+1+1)=11
(1+1+1)的由来
2-1=1
4-3=1
6-5=1


#include <bits/stdc++.h>
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define db printf("where!\n");
#define pb push_back
using namespace std;
#define ll long long
ll gcd(ll x,ll y){return y ? gcd(y,x%y) : x;}
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}

int main()
{
while(t--){
if(n%4) cout<<"NO"<<endl;
else{
cout<<"YES"<<endl;
for(int i=2;i<=n;i+=2) cout<<i<<" ";
for(int i=1;i<n/2;i+=2) cout<<i<<" ";
for(int i=n/2+3;i<n;i+=2) cout<<i<<" ";
cout<<n+1<<endl;
}
}
return 0;
}


C - Alternating Subsequence CodeForces - 1343C

#include <bits/stdc++.h>
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define db printf("where!\n");
#define pb push_back
using namespace std;
#define ll long long
ll gcd(ll x,ll y){return y ? gcd(y,x%y) : x;}
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int a[200005];
int main()
{
while(t--){
ll ans=0;
for(int i=1;i<=n;){
if(a[i]>0){
int ma=a[i];
while(a[i]>0) {
ma=max(ma,a[i]),i++;
if(i==n+1) break;
}
ans+=ma;
}
else {
int mi=a[i];
while(a[i]<0) {
mi=max(mi,a[i]),i++;
if(i==n+1) break;
}
ans+=mi;
}
}
cout<<ans<<endl;
}
return 0;
}


D - 最小长方形 HDU - 1859

#include<bits/stdc++.h>
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define pi 3.1415926535898
using namespace std;

int main(void)
{
int a,b;
while(cin>>a>>b){
if(a==b&&a==0) break;
int aa,bb;
int ma1=a,ma2=b,mi1=a,mi2=b;
while(cin>>aa>>bb){
if(aa==bb&&aa==0) break;
ma1=max(ma1,aa);
ma2=max(ma2,bb);
mi1=min(mi1,aa);
mi2=min(mi2,bb);
}
cout<<mi1<<" "<<mi2<<" "<<ma1<<" "<<ma2<<endl;
}
return 0;
}


E - Divisibility CodeForces - 630J

#include <bits/stdc++.h>
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#include <bits/stdc++.h>
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define db printf("where!\n");
#define pb push_back
using namespace std;
#define ll long long
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}

int main()
{
ll n;cin>>n;
ll k=1;
for(ll i=2;i<=10;i++ ) k=i*k/__gcd(k,i);
cout<<n/k;
return 0;
}


F - Wrong Subtraction CodeForces - 977A

#include <bits/stdc++.h>
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define db printf("where!\n");
using namespace std;
#define ll long long
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}

int main()
{
int n,k;cin>>n>>k;
while(k--){
if(n%10==0) n/=10;
else n--;
}
cout<<n;
return 0;
}


G - 最少拦截系统 HDU - 1257

#include <stdio.h>
#include <iostream>
using namespace std;
int a[30010];
int main ()
{
int n,m;
while (scanf ("%d",&n) != EOF){
int i =1;
int j;
a[0]=33330;
for (int k=0;k<n;k++){
cin>>m;
for (j=0;j<=i;j++){	//就是这里可以二分优化
if ( a[j]>=m ){
a[j]=m;
break;
}
}
if (j>i)
a[++i] = m;
}
printf("%d\n",i);
}
return 0;
}


H - Rightmost Digit HDU - 1061

#include<bits/stdc++.h>
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define pi 3.1415926535898
using namespace std;

int main(void)
{
int n;
cin>>n;
while(n--){
int k;cin>>k;
int num=1;
int x=k%10;
int y=k;
while(y){
if(y%2==1) num=(num*x)%10;
x=(x*x)%10;
y/=2;
}
cout<<num*x%10<<endl;
}
return 0;
}


I - Parencodings POJ - 1068

#include <iostream>
#include <algorithm>
#include <iomanip>
#include"stdio.h"
#include <cstring>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#include"time.h"
#define ll long long
#define MAX_INT  ((unsigned)(-1)>>1)
using namespace std;
{
int c=0;int flag=1;
char s;
while((s=getchar())>'9'||s<'0')if(s=='-')flag=-1;
c=s-'0';
while((s=getchar())<='9'&&s>='0') c=c*10+s-'0';
return c*flag;
}
int a[10005],p[25],w[25];
int main(void)
{
int t;cin>>t;
while(t--){
int n;cin>>n;
for(int i=1;i<=n;i++) cin>>p[i];
memset(a,0,sizeof a);
memset(w,0,sizeof w);
int k=1;
for(int i=1;i<=n;i++){
for(int j=0;j<p[i]-p[i-1];j++) a[k++]=1;//左1 右0
k++;
}
int c=1;
for(int i=1;i<k;i++){
if(a[i]==0){
int num=1;
for(int j=i-1;j>0;j--){
if(a[j]==1) num--,w[c]++;
else num++;
if(num==0){
c++;
break;
}
}
}
}
for(int i=1;i<n;i++){
cout<<w[i]<<" ";
}
cout<<w[n]<<endl;
}
return 0;
}


## 彩蛋

• 点赞 1
• 评论 4
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

TA很酷

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文

03-22 114
03-29 1841
11-20 2523
04-22 2748
10-05 50
03-15 5110
11-09 103