暑期集训第一周总结"/>
暑期集训第一周总结
(一)例题记录
A-人见人爱 A ^ B
求A^B的最后三位数表示的整数。
说明:A^B的含义是“A的B次方”
Input
输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。
Output
对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。
Sample Input
2 3
12 6
6789 10000
0 0
Sample Output
8
984
1
理解
为了防止数据过大而采用取模,可直接得出后三位数字。
AC代码
#include <bits/stdc++.h>
using namespace std;int main()
{int a,b;while(~scanf("%d%d",&a,&b)){if(a==0&&b==0) break;if(b==0) cout << 1 << endl;if(a==0) cout << 0 << endl;if(a != 0&& b != 0){int s = 1;for(int i = 0;i < b;i++){s= s * a;s= s % 1000; //取模运算,防止s过大}cout << s << endl; }}return 0;
}
B-人见人爱 A - B
参加过上个月月赛的同学一定还记得其中的一个最简单的题目,就是{A}+{B},那个题目求的是两个集合的并集,今天我们这个A-B求的是两个集合的差,就是做集合的减法运算。(当然,大家都知道集合的定义,就是同一个集合中不会有两个相同的元素,这里还是提醒大家一下)
呵呵,很简单吧?
Input
每组输入数据占1行,每行数据的开始是2个整数n(0<=n<=100)和m(0<=m<=100),分别表示集合A和集合B的元素个数,然后紧跟着n+m个元素,前面n个元素属于集合A,其余的属于集合B. 每个元素为不超出int范围的整数,元素之间有一个空格隔开.
如果n=0并且m=0表示输入的结束,不做处理。
Output
针对每组数据输出一行数据,表示A-B的结果,如果结果为空集合,则输出“NULL”,否则从小到大输出结果,为了简化问题,每个元素后面跟一个空格.
Sample Input
3 3 1 2 3 1 4 7
3 7 2 5 8 2 3 4 5 6 7 8
0 0
Sample Output
2 3
NULL
理解
对a,b两个数组进行比较,若a中有b没有的数字,则存入c数组里,最后输出。
AC代码
#include <bits/stdc++.h>
using namespace std;
const int M = 100 + 5;
void bubble_sort(int*,int);int main()
{int n,m;while(scanf("%d%d",&n,&m)!=EOF){if(n == 0 && m == 0) break; int a[M],b[M],c[M],i;for(i = 0;i < n;i++)scanf("%d",&a[i]);for(i = 0;i < m;i++)scanf("%d",&b[i]);int y=0;for(i = 0;i < n;i++){ int x=0; for(int j = 0;j < m;j++){if(a[i] == b[j])x++; //当两个数组中没有相同的数字时,x=0,进入下个判断}if(x == 0){c[y] = a[i]; //将得到的目标存入新数组中y++;}} //若y==0,表示c数组为空,即a有的b都有if(y == 0){printf("NULL\n");continue;}sort(c,y + c); for(i = 0;i < y;i++){if(i == y - 1)printf("%d \n",c[i]);elseprintf("%d ",c[i]);}}return 0;
}
C-Number Sequence(HDU-1005)
Problem Description
A number sequence is defined as follows:
f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.
Given A, B, and n, you are to calculate the value of f(n).
Input
The input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000). Three zeros signal the end of input and this test case is not to be processed.
Output
For each test case, print the value of f(n) on a single line.
Sample Input
1 1 3
1 2 10
0 0 0
Sample Output
2
5
理解
为何要取模还是无法理解
AC代码
#include<stdio.h>int arr[10000];int
更多推荐
暑期集训第一周总结
发布评论