GVKun编程网logo

HDU-1041-Computer Transformation,大数递推,水过~~

1

这篇文章主要围绕HDU-1041-ComputerTransformation,大数递推,水过~~展开,旨在为您提供一份详细的参考资料。我们将全面介绍HDU-1041-ComputerTransfor

这篇文章主要围绕HDU-1041-Computer Transformation,大数递推,水过~~展开,旨在为您提供一份详细的参考资料。我们将全面介绍HDU-1041-Computer Transformation,大数递推,水过~~,同时也会为您带来1041 Be Unique、1041 数列求和、1041 考试座位号 (15 分)、1041 考试座位号 (15 分) java的实用方法。

本文目录一览:

HDU-1041-Computer Transformation,大数递推,水过~~

HDU-1041-Computer Transformation,大数递推,水过~~

                                                                              Computer Transformation
                                                                                   Time Limit: 2000/1000 MS (Java/Others)   
 Memory Limit: 65536/32768 K (Java/Others)

http://acm.hdu.edu.cn/showproblem.php?pid=1041

Problem Description

A sequence consisting of one digit,the number 1 is initially written into a computer. At each successive time step,the computer simultaneously tranforms each digit 0 into the sequence 1 0 and each digit 1 into the sequence 0 1. So,after the first time step,the sequence 0 1 is obtained; after the second,the sequence 1 0 0 1,after the third,the sequence 0 1 1 0 1 0 0 1 and so on. 

How many pairs of consequitive zeroes will appear in the sequence after n steps? 
 
Input
Every input line contains one natural number n (0 < n ≤1000).
 
Output
For each input n print the number of consecutive zeroes pairs that will appear in the sequence after n steps.

Sample Input
   
   
2 3
 
Sample Output
   
   
1 1
 
Source
Southeastern Europe 2005

    似曾相识的一题,连递推数列都是一模一样的,好醉。。

    其实举几组样例多举几组就可以发现规律了,每次出现1001这种时都是上一个序列中有01这种子串,所以看上一串有多少个01字串就知道下一个有多少个1001,所以不难发现递推公式a[i]=a[i-1]+2*a[i-2](i>=3);这个和那个填骨牌的题一模一样,但注意数据范围,就算2的1000次方也是很大的,所以用二维数组存储大数,开到400就够了;

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
//const int INF=0x3f3f3f3f;
const int N=1000+10;
int a[N][400];
int main()
{
    memset(a,sizeof(a));
    int n,i,j;
    a[1][0]=0,a[2][0]=1;
    int c=0;
    for(i=3;i<=1000;i++)
    {
        c=0;
        for(j=0;j<=400;j++)//核心--大数;
        {
            a[i][j]=a[i-1][j]+2*a[i-2][j]+c;
            c=a[i][j]/10;
            a[i][j]%=10;
        }
    }
    while(~scanf("%d",&n))
    {
        if(n==1)
            printf("0\n");
        else
        {
            for(j=399;j>=0;j--)
                if(a[n][j])
                break;
            for(i=j;i>=0;i--)
                printf("%d",a[n][i]);
            printf("\n");
        }
    }
    return 0;
}

  其实静下心来想想思路到A出这道题不过10多分钟,这如果在比赛中就会有绝对的优势

1041 Be Unique

1041 Be Unique

题目意思就是找到第一个没有重复的数,数据只有10^5,所以用数组水了一下。如果比较大的话应该要用map和vector。

#include <iostream>
#include <string.h>
#define maxn 100005
int a[maxn],b[maxn];
int main()
{
    int n,x;
    memset(a,0,sizeof(a));
    scanf("%d",&n);
    int p=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&x);
        a[x]++;
        if(a[x]==1)
            b[p++]=x;
    }
    int flag=1;
    for(int i=0;i<p;i++)
    {
        if(a[b[i]]==1)
        {
            printf("%d\n",b[i]);
            flag=0;
            break;
        }
    }
    if(flag)
        printf("None\n");
    return 0;
}
View Code

 

1041 数列求和

1041 数列求和

题目描述

输入一个整数n,输出数列1-1/3+1/5-……前n项的和。

输入

输入只有一个整数n。

输出

结果保留2为小数,单独占一行。

样例输入 Copy

3

样例输出 Copy

0.87

# include<stdio.h>
int main()
{
float sum=0.0;
int n,i;
int flag=-1; 
scanf("%d",&n);
for(i=1; i<=n; i++)
{
	flag*=-1;   //使每一项符号都发生变化,一加一减。
sum = sum + 1.0/(flag* (2*i-1));
}
printf("%.2f",sum);
return 0;
}

1041 考试座位号 (15 分)

1041 考试座位号 (15 分)

题目:

每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。

输入格式:

输入第一行给出一个正整数 N(≤1000),随后 N 行,每行给出一个考生的信息:准考证号 试机座位号 考试座位号。其中准考证号由 16 位数字组成,座位从 1 到 N 编号。输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。

考生信息之后,给出一个正整数 M(≤N),随后一行中给出 M 个待查询的试机座位号码,以空格分隔。

输出格式:

对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用 1 个空格分隔。

输入样例:

4
3310120150912233 2 4
3310120150912119 4 1
3310120150912126 1 3
3310120150912002 3 2
2
3 4

输出样例:

3310120150912002 2
3310120150912119 1

原本想尝试用 vector 容器来解决问题以增加对 c++ 函数库的应用能力,后来觉得太麻烦了还是不用了,直接上。毕竟,简单的问题还是不要复杂化,但是可以尝试多种方式解决问题以求拓展思维。

思路:

需要同时存储一个考生的准考证号、试机座位号、考试座位号这三个信息,用结构体再适合不过了。且用结构体知道一个信息查找另外几个信息相当方便。

代码:

 1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4 
 5 struct pat{
 6     string ACNumber;    //准考证号 
 7     int sjp;    //试机位置 
 8     int ep;        //考试位置 
 9 }stu[1001];
10 
11 int main()
12 {
13     int n, m;
14     cin >> n;
15     for(int i = 0; i < n; i++)
16     {
17         cin >> stu[i].ACNumber >> stu[i].sjp >> stu[i].ep;
18     }
19     cin >> m;
20     int sjpk;    //待查询试机座位 
21     while(m--)
22     {
23         cin >> sjpk;
24         for(int i = 0; i < n; i++)
25         {
26             if(sjpk == stu[i].sjp)
27                 cout << stu[i].ACNumber << " " << stu[i].ep << endl;
28          } 
29     }
30     return 0;
31  }

 总结:

几个需要存储的信息具有关联性的采用结构体。

 

1041 考试座位号 (15 分) java

1041 考试座位号 (15 分) java

每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。
输入格式:

输入第一行给出一个正整数 N(≤1000),随后 N 行,每行给出一个考生的信息:准考证号 试机座位号 考试座位号。其中准考证号由 14 位数字组成,座位从 1 到 N 编号。输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。

考生信息之后,给出一个正整数 M(≤N),随后一行中给出 M 个待查询的试机座位号码,以空格分隔。
输出格式:

对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用 1 个空格分隔。
输入样例:

4
10120150912233 2 4
10120150912119 4 1
10120150912126 1 3
10120150912002 3 2
2
3 4

输出样例:

10120150912002 2
10120150912119 1

Think

在查找考试座位号的时候不要超时,所以需要使用break

code

import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        int row = sc.nextInt();
        long[][] stu_n = new long[row][3];
        
        for(int i = 0 ; i < row ; i++) {
            stu_n[i][0] = sc.nextLong(); //准考证号 
            stu_n[i][1] = sc.nextLong(); //试机座位号 
            stu_n[i][2] = sc.nextLong(); //考试座位号
        }
        
        int number = sc.nextInt(); //查找人数
        
        for(int j = 0 ; j < number ; j++) {            
            int id = sc.nextInt();
            for(int k = 0 ; k < row ; k++)
                if(id == stu_n[k][1]) {
                    System.out.println(stu_n[k][0] + " " + stu_n[k][2]);
                    break; //找到后立刻停止本层循环
                }
        }
    
    }
}

关于HDU-1041-Computer Transformation,大数递推,水过~~的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于1041 Be Unique、1041 数列求和、1041 考试座位号 (15 分)、1041 考试座位号 (15 分) java的相关信息,请在本站寻找。

本文标签:

上一篇(大数)Computer Transformation hdu1041((大数一小数)÷单位1的量例题)

下一篇HDU-1041-Computer Transformation(规律题 && 大数题)(规律数学题5011)