1cf136div2

今天A了两题,A和C题,B题第五组测试数据没过去,也在比赛的时候找到原因了。。。

A题就是先输出n然后输出1到n-1一开始就理解错了以为是直接输出n到1,还奇怪为什么他还说是升序,这不是矛盾吗?果然是自己的问题,题目是不会出现矛盾的,。。这样A题就是水题了,只要读懂题目就简单了。。

A. Little Elephant and Function
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The Little Elephant enjoys recursive functions.

This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows:

  • If x = 1, exit the function.
  • Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a).

The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order.

Input

A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation.

Output

In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces.

It is guaranteed that the answer exists.

Sample test(s)
Input
1
Output
1 
Input
2
Output
2 1 

#include <iostream>
#include<cstdio>
#include<cstring>
int a[1010],b[1010];
using namespace std;

int main()
{
 int n;
 while(scanf("%d",&n)!=EOF)
 {
  int i;
  printf("%d ",n);
  for(i=1;i<=n-1;i++)
  {
   a[i]=i;
   printf("%d ",a[i]);
  }
  printf("\n");

 }
 return 0;
}

 

C题;

c题的话确实敲了挺久的不过还是为自己把敲代码过程中碰到的问题并能够处理掉而高兴,毕竟自己进步了。。

C 题我是一后面的提示为突破口的,就是判断给定的一组数是否存在只调换<=1次,就会是新得到的数组里的数按照升序排列。。

C. Little Elephant and Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.

The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array a, only if array a can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements.

Help the Little Elephant, determine if he could have accidentally changed the array a, sorted by non-decreasing, himself.

Input

The first line contains a single integer n (2 ≤ n ≤ 105) — the size of array a. The next line contains n positive integers, separated by single spaces and not exceeding 109, — array a.

Note that the elements of the array are not necessarily distinct numbers.

Output

In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.

Sample test(s)
Input
2
1 2
Output
YES
Input
3
3 2 1
Output
YES
Input
4
4 3 2 1
Output
NO
Note

In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".

In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".

In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".

C代码AC

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int b[100001],a[100001],c[100001];
int main()
{
 int n;
 int i;
 while(scanf("%d",&n)!=EOF)
 {
  memset(a,0,sizeof(a));
  memset(c,0,sizeof(c));
  memset(b,0,sizeof(b));
  int count=0;
  for(i=1;i<=n;i++)
  {
   scanf("%d",&b[i]);
   a[i]=b[i];
  }
  sort(a+1,a+n+1);
  int j=0;
  int flag=0;
  for(i=1;i<=n;i++)
  {
   if(b[i]!=a[i])
   {
    count++;
   }
  }
  if(count>2)
   printf("NO\n");
  //else if(a[0]==c[1]&&a[1]==c[0]&&count==2)
  // printf("YES\n");
  else
   printf("YES\n");
 }
 return 0;
}

 

 

B题的话是找他的因子和他本身要有至少一个相同的数?

先把代码贴一下,明天在看看问题出错在哪里。。

B. Little Elephant and Numbers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The Little Elephant loves numbers.

He has a positive integer x. The Little Elephant wants to find the number of positive integers d, such that d is the divisor of x, and x and d have at least one common (the same) digit in their decimal representations.

Help the Little Elephant to find the described number.

Input

A single line contains a single integer x (1 ≤ x ≤ 109).

Output

In a single line print an integer — the answer to the problem.

Sample test(s)
Input
1
Output
1
Input
10
Output
2

#include <iostream>
#include<cstdio>
using namespace std;
#define maxn 1000001
char  a[maxn];
int main()
{
 int n;
 while(scanf("%d",&n)!=EOF)
 {
  int m=n;
  int i,j,k=0;
       int count=0;
       while(n!=0)
       {
        a[k]=n;
    //printf("%d\n",a[i]);
    k++;
        n=n/10;
       }
   int t;
  for(i=1;i<=m;i++)
  {
   if(m%i==0)
   {
    //printf("%d\n",i);
    t=i;
    for(j=0;j<k;j++)
    {
     if(t==a[j])
     {
      count++;
      break;
     }
       if(j>=k)
       {
        t=i/10;
        j=0;
       }
    }
   }
  }
  printf("%d\n",count);
 }
 return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值