整理一下训练题目
画8
Time Limit: 1000 ms /Memory Limit: 32768 kb
Description
谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发.
Input
输入的第一行为一个整数N,表示后面有N组数据.
每组数据中有一个字符和一个整数,字符表示画笔,整数(>=5)表示高度.
Output
画横线总是一个字符粗,竖线随着总高度每增长6而增加1个字符宽.当总高度从5增加到6时,其竖线宽度从1增长到2.下圈高度不小于上圈高度,但应尽量接近上圈高度,且下圈的内径呈正方形.
每画一个"8"应空一行,但最前和最后都无空行.
Sample Input
Sample Output
这道题真不算难,赛后一敲就敲出来了,但是三个人一起就各种错。
吐槽一下结尾不能有空行。
#include <iostream>
using namespace std;
int main()
{
int n, m;
char c;
int h1, h2, k1, k2;
cin >> n;
while(n--){
cin >> c >> m;
h1 = (m - 1) / 2;
h2 = m / 2;
k1 = m / 6 + 1;
k2 = h2 - 1;
for(int i = 0; i < k1; i++)
cout << ' ';
for(int i = 0; i < k2; i++)
cout << c;
cout << '\n';
for(int i = 1; i < h1; i++){
for(int i = 0; i < k1; i++)
cout << c;
for(int i = 0; i < k2; i++)
cout << ' ';
for(int i = 0; i < k1; i++)
cout << c;
cout << '\n';
}
for(int i = 0; i < k1; i++)
cout << ' ';
for(int i = 0; i < k2; i++)
cout << c;
cout << '\n';
for(int i = 1; i < h2; i++){
for(int i = 0; i < k1; i++)
cout << c;
for(int i = 0; i < k2; i++)
cout << ' ';
for(int i = 0; i < k1; i++)
cout << c;
cout << '\n';
}
for(int i = 0; i < k1; i++)
cout << ' ';
for(int i = 0; i < k2; i++)
cout << c;
cout << '\n';
if(n)
cout << '\n';
}
return 0;
}
最少拦截系统
Time Limit: 1000 ms /Memory Limit: 32768 kb
Description
某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
Input
输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔)
Output
对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统.
Sample Input
Sample Output
裸的最长上升子序列,但是大佬队友忘了lower_bound的写法了,我DP又是菜鸡,交了发n^2过了。
#include <algorithm>
#include <cstdio>
using namespace std;
#define N 100000
#define INF 100000000
int a[N], dp[N], l = 0;
int main()
{
while(scanf("%d", &l) != EOF){
for(int i = 0; i < l; i++)
scanf("%d", &a[i]);
fill(dp, dp + l, INF);
for(int i = 0; i < l; i++)
*lower_bound(dp, dp + l, a[i]) = a[i];
printf("%d\n", lower_bound(dp, dp + l, INF) - dp);
}
return 0;
}
Sum It Up
Time Limit: 1000 ms /Memory Limit: 32768 kb
Description
Given a specified total t and a list of n integers, find all distinct sums using numbers from the list that add up to t. For example, if t=4, n=6, and the list is [4,3,2,2,1,1], then there are four different sums that equal 4: 4,3+1,2+2, and 2+1+1.(A number can be used within a sum as many times as it appears in the list, and a single number counts as a sum.) Your job is to solve this problem in general.
Input
The input will contain one or more test cases, one per line. Each test case contains t, the total, followed by n, the number of integers in the list, followed by n integers x1,...,xn. If n=0 it signals the end of the input; otherwise, t will be a positive integer less than 1000, n will be an integer between 1 and 12(inclusive), and x1,...,xn will be positive integers less than 100. All numbers will be separated by exactly one space. The numbers in each list appear in nonincreasing order, and there may be repetitions.
Output
For each test case, first output a line containing 'Sums of', the total, and a colon. Then output each sum, one per line; if there are no sums, output the line 'NONE'. The numbers within each sum must appear in nonincreasing order. A number may be repeated in the sum as many times as it was repeated in the original list. The sums themselves must be sorted in decreasing order based on the numbers appearing in the sum. In other words, the sums must be sorted by their first number; sums with the same first number must be sorted by their second number; sums with the same first two numbers must be sorted by their third number; and so on. Within each test case, all sums must be distince; the same sum connot appear twice.
Sample Input
Sample Output
裸的枚举子集加判重题目,我后来用map状态压缩判重。
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define N 105
int n, m, a[15];
bool used[N], flag;
int path[15], l = 0, sum;
map<string, bool> mp;
string tmp;
string to_String(int x)
{
string ans = "";
while(x){
ans += char('0' + x % 10);
x /= 10;
}
reverse(ans.begin(), ans.end());
return ans;
}
void dfs(int x)
{
if(x == m){
sum = 0;
l = 0;
tmp = "";
for(int i = 1; i < N; i++){
if(used[i]){
path[l++] = a[i];
sum += a[i];
tmp += to_String(a[i]);
}
}
if(sum == n && mp[tmp] == false){
for(int i = 0; i < l; i++){
printf("%d%c", path[i], i == l - 1?'\n':'+');
}
flag = true;
}
mp[tmp] = true;
return;
}
used[x + 1] = true;
dfs(x + 1);
used[x + 1] = false;
dfs(x + 1);
}
int main()
{
while(scanf("%d%d", &n, &m) && n + m){
for(int i = 1; i <= m; i++){
scanf("%d", &a[i]);
}
flag = false;
mp.clear();
memset(used, 0, sizeof used);
printf("Sums of %d:\n", n);
dfs(0);
if(!flag)
printf("NONE\n");
}
return 0;
}
Tickets
Time Limit: 1000 ms /Memory Limit: 32768 kb
Description
Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a tuff time for Joe who sells the film tickets. He is wandering when could he go back home as early as possible.
A good approach, reducing the total time of tickets selling, is let adjacent people buy tickets together. As the restriction of the Ticket Seller Machine, Joe can sell a single ticket or two adjacent tickets at a time.
Since you are the great JESUS, you know exactly how much time needed for every person to buy a single ticket or two tickets for him/her. Could you so kind to tell poor Joe at what time could he go back home as early as possible? If so, I guess Joe would full of appreciation for your help.
Input
There are N(1<=N<=10) different scenarios, each scenario consists of 3 lines:
1) An integer K(1<=K<=2000) representing the total number of people;
2) K integer numbers(0s<=Si<=25s) representing the time consumed to buy a ticket for each person;
3) (K-1) integer numbers(0s<=Di<=50s) representing the time needed for two adjacent people to buy two tickets together.
Output
For every scenario, please tell Joe at what time could he go back home as early as possible. Every day Joe started his work at 08:00:00 am. The format of time is HH:MM:SS am|pm.
Sample Input
Sample Output
动态规划的题目,状态转移方程很好写。队友当时写的二维,赛后我现在贴个一维的。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define N 2005
#define INF 100000000
int dp[N], n, k, a[N], b[N];
int h, m, s;
int main()
{
scanf("%d", &n);
while(n--){
scanf("%d", &k);
for(int i = 1; i <= k; i++){
scanf("%d", &a[i]);
}
for(int i = 2; i <= k; i++){
scanf("%d", &b[i]);
}
fill(dp, dp + N, INF);
dp[0] = 0;
dp[1] = a[1];
for(int j = 2; j <= k; j++){
dp[j] = min(dp[j - 2] + b[j], dp[j - 1] + a[j]);
}
s = dp[k] % 60;
dp[k] -= s;
m = dp[k] / 60;
h = 8 + m / 60;
m -= (h - 8) * 60;
if(h < 12 || h == 12 && m == 0 && s == 0)
printf("%02d:%02d:%02d am\n", h, m, s);
else
printf("%02d:%02d:%02d pm\n", h, m, s);
}
return 0;
}
字串数
Time Limit: 1000 ms /Memory Limit: 32768 kb
Description
一个A和两个B一共可以组成三种字符串:"ABB","BAB","BBA".
给定若干字母和它们相应的个数,计算一共可以组成多少个不同的字符串.
Input
每组测试数据分两行,第一行为n(1<=n<=26),表示不同字母的个数,第二行为n个数A1,A2,...,An(1<=Ai<=12),表示每种字母的个数.测试数据以n=0为结束.
Output
对于每一组测试数据,输出一个m,表示一共有多少种字符串.
Sample Input
Sample Output
我还是找不到我代码BUG在哪儿,队友分解质因数过的,我代码就是WA,无法接受。
贴一波队友代码。
希望有大佬把我的错误找到,注释的是我的代码。
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int gao[10000],n,m,x,y,z,k,l,s,da[1000],xiao[1000],a[1000];
int su[100]={0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311};
void dafen(int x)
{
for (int i=1; i<=64; i++)
{
while (x%su[i]==0)
{
x/=su[i];
da[su[i]]++;
}
}
}
void xiaofen(int x)
{
for (int i=1; i<=9; i++)
{
while (x%su[i]==0)
{
x/=su[i];
xiao[su[i]]++;
}
}
}
int main()
{
//freopen("in.txt", "r", stdin);
freopen("date.txt", "r", stdin);
while (true)
{
scanf("%d", &n);
if (n==0) break;
for (int i=1; i<=100; i++) gao[i]=0;
s=0;
for (int i=1; i<=500; i++)
{
da[i]=0;
xiao[i]=0;
}
for (int i=1; i<=n; i++)
{
cin>>a[i];
s+=a[i];
}
for (int i=2; i<=s; i++) dafen(i);
for (int i=1; i<=n; i++)
{
for (int i=1; i<=26; i++) xiao[i]=0;
for (int j=1; j<=a[i]; j++) xiaofen(j);
for (int i=1; i<=23; i++)
{
if (xiao[i])
{
da[i]-=xiao[i];
}
}
}
l=1;
gao[1]=1;
x=0;
for (int i=1; i<=64; i++)
{
for (int j=1; j<=da[su[i]]; j++)
{
for (int k=1; k<=l; k++)
{
gao[k]=gao[k]*su[i]+x;
x=gao[k]/10;
gao[k]%=10;
}
while (x)
{
l++;
gao[l]=x%10;
x=x/10;
}
}
}
//cout<<l;
//for (int i=1; i<=9; i++) cout<<da[su[i]]<<" ";
//cout << l << endl;
for (int i=l; i>=1; i--) printf("%d", gao[i]);
printf("\n");
}
return 0;
}
/**
#include <iostream>
#include <string>
#include <map>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
const int mod = 100000007;
const double eps = 1e-8;
#define N 1000
int n, a[30], b[400], c[N], sum;
int main()
{
// freopen("date.txt", "r", stdin);
while(scanf("%d", &n) != EOF && n){
sum = 0;
for(int i = 0; i < n; i++){
scanf("%d", &a[i]);
sum += a[i];
}
for(int i = 1; i <= sum; i++)
b[i] = i;
for(int i = 0; i < n; i++){
for(int j = 2; j <= a[i]; j++){
for(int k = j; k <= sum; k += j){
if(b[k] % j == 0){
b[k] /= j;
break;
}
}
}
}
fill(c, c + N, 0);
c[0] = 1;
int l = 0;
for(int i = 1; i <= sum; i++){
if(b[i] == 1)
continue;
for(int j = 0; j <= l; j++){
c[j] *= b[i];
}
int x = 0;
for(int j = 0; j <= l; j++){
c[j] += x;
x = c[j] / 10;
c[j] %= 10;
}
l++;
while(x){
c[l] = x % 10;
x /= 10;
l++;
}
}
while(l > 0 && c[l - 1] == 0)
l--;
//cout << l << endl;
for(int i = l - 1; i >= 0; i--)
printf("%d", c[i]);
printf("\n");
}
return 0;
}
*/
水果
Time Limit: 1000 ms /Memory Limit: 32768 kb
Description
夏天来了~~好开心啊,呵呵,好多好多水果~~
Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了.
Input
第一行正整数N(0<N<=10)表示有N组测试数据.
每组测试数据的第一行是一个整数M(0<M<=100),表示工有M次成功的交易.其后有M行数据,每行表示一次交易,由水果名称(小写字母组成,长度不超过80),水果产地(小写字母组成,长度不超过80)和交易的水果数目(正整数,不超过100)组成.
Output
对于每一组测试数据,请你输出一份排版格式正确(请分析样本输出)的水果销售情况明细表.这份明细表包括所有水果的产地,名称和销售数目的信息.水果先按产地分类,产地按字母顺序排列;同一产地的水果按照名称排序,名称按字母顺序排序.
两组测试数据之间有一个空行.最后一组测试数据之后没有空行.
Sample Input
Sample Output
都是用string排序,就是map里面套map。
吐槽末尾无空行。
还有迭代器竟然不支持+1操作,简直了。
#include <iostream>
#include <string>
#include <map>
#include <cstdio>
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
const int mod = 100000007;
const double eps = 1e-8;
#define N 10000
struct node
{
map<string, int> mp;
};
map<string, node> mp;
int main()
{
//freopen("date.txt", "r", stdin);
int t, n;
string a, b;
int c;
node tmp;
scanf("%d", &t);
while(t--)
{
mp.clear();
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> a >> b >> c;
if(mp.count(b))
{
mp[b].mp[a] += c;
}
else
{
tmp.mp.clear();
tmp.mp[a] = c;
mp[b] = tmp;
}
//cout << mp.size() << endl;
}
map<string, node>::iterator it;
// for(it = mp.begin(); it != mp.end(); ++it)
// cout << it->first << endl;
map<string, int>::iterator ite;
for(it = mp.begin(); it != mp.end(); ++it)
{
cout << it->first << endl;
for(ite = it->second.mp.begin(); ite != it->second.mp.end(); ++ite)
{
cout << " |----" << ite->first << "(" << ite->second << ")";
if(++it != mp.end()){
printf("\n");
--it;
continue;
}
--it;
if(++ite != it->second.mp.end()){
printf("\n");
--ite;
continue;
}
--ite;
printf("\n");
}
}
if(t){
printf("\n");
}
}
return 0;
}
Counting Squares
Time Limit: 1000 ms /Memory Limit: 32768 kb
Description
Your input is a series of rectangles, one per line. Each rectangle is specified as two points(X,Y) that specify the opposite corners of a rectangle. All coordinates will be integers in the range 0 to 100. For example, the line
5 8 7 10
specifies the rectangle who's corners are(5,8),(7,8),(7,10),(5,10).
If drawn on graph paper, that rectangle would cover four squares. Your job is to count the number of unit(i.e.,1*1) squares that are covered by any one of the rectangles given as input. Any square covered by more than one rectangle should only be counted once.
Input
The input format is a series of lines, each containing 4 integers. Four -1's are used to separate problems, and four -2's are used to end the last problem. Otherwise, the numbers are the x-ycoordinates of two points that are opposite corners of a rectangle.
Output
Your output should be the number of squares covered by each set of rectangles. Each number should be printed on a separate line.
Sample Input
5 8 7 10 6 9 7 8 6 8 8 11 -1 -1 -1 -1 0 0 100 100 50 75 12 90 39 42 57 73 -2 -2 -2 -2
Sample Output
8 10000
队友说他先写一发暴力,让我想办法剪枝,恩然后暴力过了,恩……
我赛后也自己写了一发暴力。
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
struct ret{
int u, d, l, r;
};
bool maze[101][101];
int x1, y1, x2, y2, ans;
ret change(int a, int b, int c, int d)
{
ret ans;
ans.u = max(b, d);ans.d = min(b, d);
ans.r = max(a, c);ans.l = min(a, c);
return ans;
}
void solve(const ret & u)
{
for(int i = u.d; i < u.u; i++){
for(int j = u.l; j < u.r; j++){
if(!maze[i][j]){
maze[i][j] = true;
ans++;
// cout << i <<' ' <<j << endl;
}
}
}
}
int main()
{
while(true){
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
if(x1 == -1){
printf("%d\n", ans);
ans = 0;
memset(maze, false, sizeof maze);
continue;
}
if(x1 == -2){
printf("%d\n", ans);
break;
}
solve(change(x1, y1, x2, y2));
}
return 0;
}
/*
0 0 100 100
50 75 12 90
39 42 57 73
-2 -2 -2 -2*/
Floating Point Presentation
Time Limit: 1000 ms /Memory Limit: 32768 kb
Description
Do you know IEEE's constact of single floating point data? If you are not sure, following is the contract:
This problem is really simple for you: please convert the real data into the IEEE single floating point data presentation.
Input
There are N(1<=N<=150) real data need to be converted. Real data can be negative, zero, and positive.
Output
For each real data, print the IEEE single floating point data presentation in upper case hexadecimal letters in a single line.
Sample Input
2 23.85 -23.85
Sample Output
41BECCCD C1BECCCD
超级模拟题,给个浮点数输出他的内部存储方式,超级6看不懂.
然而c里面有内存复制函数,Orz。
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
int n,x;
float m;
cin >> n;
while(n--)
{
cin >> m;
memcpy(&x, &m, sizeof(m));
printf("%X\n", x);
}
return 0;
}
这是草草保存的代码。
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
const int mod = 100000007;
const double eps = 1e-8;
#define N 10000
int a[10000],dp[10000],n,m,x,y,z,k,l;
int main()
{
while (scanf("%d", &n)!=EOF)
{
//freopen("date.txt", "r", stdin);
for (int i=1; i<=n; i++) scanf("%d", &a[i]);
dp[1]=1;
int ans=0;
for (int i=2; i<=n; i++)
{
dp[i]=1;
for (int j=1; j<i; j++)
if (a[i]>a[j] && dp[i]<dp[j]+1)
{
dp[i]=dp[j]+1;
if (ans<dp[i]) ans=dp[i];
}
}
printf("%d\n", ans);
}
return 0;
}
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
const int mod = 100000007;
const double eps = 1e-8;
#define N 10000
int main()
{
// freopen("date.txt", "r", stdin);
int t, m, j = 2, a, b;
scanf("%d", &t);
while(t--){
scanf("%d", &m);
j = 2;
for(int i = 0; i < m; i++){
scanf("%d%d", &a, &b);
if(a == j){
j = b;
}else if(b == j){
j = a;
}
}
printf("%d\n", j);
}
return 0;
}
#include<iostream> #include<cstdio> int map[10010]; using namespace std; void init(){ map[0]=1; map[1]=1; for(int i=2;i<=10000;i++){ if(map[i]==0){ int j=2; while(i*j<10000){ map[i*j]=1; j++; } } } return ; } int main(){ //freopen("1.txt","r",stdin); init(); int n; while(cin>>n){ int i=n/2,j=n/2; while(1){ if(map[i]==0&&map[j]==0){ cout<<i<<" "<<j<<endl; break; } else { i--; j++; } } } return 0; }
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; int n,m,x,y,z,k,l,p,h; char c; int main() { //freopen("in.txt","r",stdin); cin>>n; while (n--) { cin>>c>>h; if (h%2) { k=h/6+1; int zhong=(h-3)/2; for (int i=1; i<=k; i++) cout<<" "; for (int i=1; i<=zhong; i++) cout<<c; cout<<endl; for (int i=1; i<=zhong; i++) { for (int j=1; j<=k; j++) cout<<c; for (int j=1; j<=zhong; j++) cout<<" "; for (int j=1; j<=k; j++) cout<<c; cout<<endl; } for (int i=1; i<=k; i++) cout<<" "; for (int i=1; i<=zhong; i++) cout<<c; cout<<endl; for (int i=1; i<=zhong; i++) { for (int j=1; j<=k; j++) cout<<c; for (int j=1; j<=zhong; j++) cout<<" "; for (int j=1; j<=k; j++) cout<<c; cout<<endl; } for (int i=1; i<=k; i++) cout<<" "; for (int i=1; i<=zhong; i++) cout<<c; if (n!=0) cout<<endl<<endl; } if (h%2==0) { k=h/6+1; int zhong=(h-4)/2+1; for (int i=1; i<=k; i++) cout<<" "; for (int i=1; i<=zhong; i++) cout<<c; cout<<endl; for (int i=1; i<=zhong-1; i++) { for (int j=1; j<=k; j++) cout<<c; for (int j=1; j<=zhong; j++) cout<<" "; for (int j=1; j<=k; j++) cout<<c; cout<<endl; } for (int i=1; i<=k; i++) cout<<" "; for (int i=1; i<=zhong; i++) cout<<c; cout<<endl; for (int i=1; i<=zhong; i++) { for (int j=1; j<=k; j++) cout<<c; for (int j=1; j<=zhong; j++) cout<<" "; for (int j=1; j<=k; j++) cout<<c; cout<<endl; } for (int i=1; i<=k; i++) cout<<" "; for (int i=1; i<=zhong; i++) cout<<c; if (n!=0) cout<<endl<<endl; } } cout<<endl; return 0; }
#include <iostream> #include <string> #include <map> #include <cstdio> using namespace std; typedef long long ll; //typedef pair<int, int> P; const int mod = 100000007; const double eps = 1e-8; #define N 10000 struct node { map<string, int> mp; }; map<string, node> mp; int main() { //freopen("date.txt", "r", stdin); int t, n; string a, b; int c; node tmp; scanf("%d", &t); while(t--) { mp.clear(); cin >> n; for(int i = 0; i < n; i++) { cin >> a >> b >> c; if(mp.count(b)) { mp[b].mp[a] += c; } else { tmp.mp.clear(); tmp.mp[a] = c; mp[b] = tmp; } //cout << mp.size() << endl; } map<string, node>::iterator it; // for(it = mp.begin(); it != mp.end(); ++it) // cout << it->first << endl; map<string, int>::iterator ite; for(it = mp.begin(); it != mp.end(); ++it) { cout << it->first << endl; for(ite = it->second.mp.begin(); ite != it->second.mp.end(); ++ite) { cout << " |----" << ite->first << "(" << ite->second << ")"; if(++it != mp.end()){ printf("\n"); --it; continue; } --it; if(++ite != it->second.mp.end()){ printf("\n"); --ite; continue; } --ite; printf("\n"); } } if(t){ printf("\n"); } } return 0; }
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int n,t,map[15],dabook[1010],lei,jilu; int book[15]; void dfs(int x,int ans,int ge){ if(x==lei+1){ if(ans!=t) return ; int mark=0; for(int i=1;i<=lei;i++){ for(int j=1;j<=book[i];j++){ if(mark==0){ cout<<map[i]; mark++; } else { cout<<"+"<<map[i]; } } } jilu++; cout<<endl; return ; } else { if(ge){ book[x]++; dfs(x,ans+map[x],ge-1); book[x]--; } dfs(x+1,ans,dabook[map[x+1]]); } return ; } int main(){ //freopen("1.txt","r",stdin); while(cin>>t>>n&&t&&n){ jilu=0; lei=0; cout<<"Sums of "<<t<<":"<<endl; memset(dabook,0,sizeof(dabook)); memset(book,0,sizeof(book)); int a; for(int i=1;i<=n;i++){ cin>>a; if(dabook[a]==0){ lei++; map[lei]=a; } dabook[a]++; } dfs(1,0,dabook[map[1]]); if(jilu==0){ cout<<"NONE"<<endl; } } return 0; }
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int n,k,dp[2020][2],td[2020],ts[2020]; void dph(){ dp[0][0]=0; dp[0][1]=0; for(int i=1;i<=k;i++){ dp[i][0]=min(dp[i-1][0]+td[i],dp[i-1][1]+td[i]); if(i-2>=0){ dp[i][1]=min(dp[i-2][0]+ts[i],dp[i-2][1]+ts[i]); } } return ; } void out(){ for(int i=1;i<=k;i++){ cout<<i<<" "<<dp[i][0]<<" "<<dp[i][1]<<endl; } return ; } int main(){ //freopen("1.txt","r",stdin); cin>>n; for(int i=1;i<=n;i++){ memset(dp,0x3f,sizeof(dp)); cin>>k; for(int j=1;j<=k;j++){ cin>>td[j]; } for(int j=2;j<=k;j++){ cin>>ts[j]; } dph(); int minn=min(dp[k][0],dp[k][1]); int xx,yy,zz; zz=minn%60; yy=minn/60; xx=yy/60; yy%=60; int kk=0; if(xx>=12) kk=1; if(xx>=13) xx%=12; if(xx+8<10) cout<<0; cout<<xx+8<<":"; if(yy<10) cout<<0; cout<<yy<<":"; if(zz<10) cout<<0; cout<<zz; if(kk){ cout<<" pm"<<endl; } else cout<<" am"<<endl;\ } return 0; }
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int map[110][110],anss,dx[4]={0,0,1,-1},dy[4]={1,-1,0,0}; int x1,x2,y1,y2; void bl(){ for(int i=x1+1;i<=x2;i++){ for(int j=y1+1;j<=y2;j++){ if(map[i][j]==0){ anss++; map[i][j]=1; } } } return ; } void out(){ for(int i=1;i<=15;i++){ for(int j=1;j<=15;j++){ cout<<map[i][j]<<" "; } cout<<endl; } return ; } int main(){ // freopen("1.txt","r",stdin); while(cin>>x1>>y1>>x2>>y2){ if(x1==-2){ cout<<anss<<endl; break; } if(x1==-1){ cout<<anss<<endl; anss=0; memset(map,0,sizeof(map)); } else { if(x1>x2){ int cc=x1; x1=x2; x2=cc; } if(y1>y2){ int cc=y1; y1=y2; y2=cc; } bl(); } } }
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; int gao[10000],n,m,x,y,z,k,l,s,da[1000],xiao[1000],a[1000]; int su[100]={0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311}; void dafen(int x) { for (int i=1; i<=64; i++) { while (x%su[i]==0) { x/=su[i]; da[su[i]]++; } } } void xiaofen(int x) { for (int i=1; i<=9; i++) { while (x%su[i]==0) { x/=su[i]; xiao[su[i]]++; } } } int main() { //freopen("in.txt", "r", stdin); while (true) { scanf("%d", &n); if (n==0) break; for (int i=1; i<=100; i++) gao[i]=0; s=0; for (int i=1; i<=500; i++) { da[i]=0; xiao[i]=0; } for (int i=1; i<=n; i++) { cin>>a[i]; s+=a[i]; } for (int i=2; i<=s; i++) dafen(i); for (int i=1; i<=n; i++) { for (int i=1; i<=26; i++) xiao[i]=0; for (int j=1; j<=a[i]; j++) xiaofen(j); for (int i=1; i<=23; i++) { if (xiao[i]) { da[i]-=xiao[i]; } } } l=1; gao[1]=1; x=0; for (int i=1; i<=64; i++) { for (int j=1; j<=da[su[i]]; j++) { for (int k=1; k<=l; k++) { gao[k]=gao[k]*su[i]+x; x=gao[k]/10; gao[k]%=10; } while (x) { l++; gao[l]=x%10; x=x/10; } } } //cout<<l; //for (int i=1; i<=9; i++) cout<<da[su[i]]<<" "; for (int i=l; i>=1; i--) printf("%d", gao[i]); printf("\n"); } return 0; }