周赛题解

A - An easy problem

Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status Practice HDU 2601

Description

When Teddy was a child , he was always thinking about some simple math problems ,such as “What it’s 1 cup of water plus 1 pile of dough ..” , “100 yuan buy 100 pig” .etc.. 

One day Teddy met a old man in his dream , in that dream the man whose name was“RuLai” gave Teddy a problem :

Given an N , can you calculate how many ways to write N as i * j + i + j (0 < i <= j) ?

Teddy found the answer when N was less than 10…but if N get bigger , he found it was too difficult for him to solve. 
Well , you clever ACMers ,could you help little Teddy to solve this problem and let him have a good dream ?

Input

The first line contain a T(T <= 2000) . followed by T lines ,each line contain an integer N (0<=N <= 10 10).

Output

For each case, output the number of ways in one line.

Sample Input

2
1
3

Sample Output

0
1

代码;

 1 #include<stdio.h>
 2 #include<math.h>
 3 const int MAXN=100010;
 4 int main(){
 5     __int64 N,ans;
 6     int T;
 7     scanf("%d",&T);
 8     while(T--){
 9         ans=0;
10         scanf("%I64d",&N);
11         N++;
12         int flot=0;
13         for(int i=2;i<=sqrt(N);i++)if(N%i==0)ans++;
14         printf("%I64d\n",ans);
15     }
16     return 0;
17 }

C - 最少拦截系统

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status Practice HDU 1257

Description

某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹. 
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.

Input

输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔)

Output

对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统.

Sample Input

8 389 207 155 300 299 170 158 65

Sample Output

2

代码:

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<vector>
 4 #include<algorithm>
 5 using namespace std;
 6 const int MAXN=30010;
 7 vector<int>vec;
 8 int main(){
 9     int N,x;
10     while(~scanf("%d",&N)){
11         int top=0;
12         vec.clear();
13         for(int i=0;i<N;i++){
14             scanf("%d",&x);
15         if(lower_bound(vec.begin(),vec.end(),x)==vec.end())vec.push_back(x);
16         else *lower_bound(vec.begin(),vec.end(),x)=x;
17         }
18         printf("%d\n",vec.size());
19     }
20     return 0;
21 }

G - Ignatius and the Princess III

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status Practice HDU 1028

Description

"Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says.

"The second problem is, given an positive integer N, we define an equation like this: 
  N=a[1]+a[2]+a[3]+...+a[m]; 
  a[i]>0,1<=m<=N; 
My question is how many different equations you can find for a given N. 
For example, assume N is 4, we can find: 
  4 = 4; 
  4 = 3 + 1; 
  4 = 2 + 2; 
  4 = 2 + 1 + 1; 
  4 = 1 + 1 + 1 + 1; 
so the result is 5 when N is 4. Note that "4 = 3 + 1" and "4 = 1 + 3" is the same in this problem. Now, you do it!"

Input

The input contains several test cases. Each test case contains a positive integer N(1<=N<=120) which is mentioned above. The input is terminated by the end of file.

Output

For each test case, you have to output a line contains an integer P which indicate the different equations you have found.

Sample Input

4
10
20

Sample Output

5
42
627

代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 int main(){
 4     int N,a[150],b[150];
 5     while(~scanf("%d",&N)){
 6         for(int i=0;i<=N;i++)a[i]=1,b[i]=0;
 7         for(int i=2;i<=N;i++){
 8             for(int j=0;j<=N;j++){
 9                  b[j]+=a[j];
10                 for(int k=i;j+k<=N;k+=i){
11                     b[j+k]+=a[j];
12                 }
13             }
14             for(int j=0;j<=N;j++)
15                 a[j]=b[j],b[j]=0;
16         }
17         printf("%d\n",a[N]);
18     }
19     return 0;
20 }

H - Charm Bracelet

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit Status Practice POJ 3624

Description

Bessie has gone to the mall‘s jewelry store and spies a charm bracelet. Of course, she‘d like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the supplied list has a weight Wi (1 ≤ Wi ≤ 400), a ‘desirability‘ factor Di (1 ≤ Di ≤ 100), and can be used at most once. Bessie can only support a charm bracelet whose weight is no more than M (1 ≤ M ≤ 12,880).

Given that weight limit as a constraint and a list of the charms with their weights and desirability rating, deduce the maximum possible sum of ratings.

Input

* Line 1: Two space-separated integers: N and M
* Lines 2..N+1: Line i+1 describes charm i with two space-separated integers: Wi and Di

Output

* Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints

Sample Input

4 6
1 4
2 6
3 12
2 7

Sample Output

23代码:
 1 #include<stdio.h>
 2 #include<string.h>
 3 const int MAXN=200000;
 4 int bag[MAXN];
 5 #define MAX(x,y)(x>y?x:y)
 6 struct Node{
 7     int w,v;
 8 };
 9 Node dt[5000];
10 int main(){
11     int N,M;
12     while(~scanf("%d%d",&N,&M)){
13         memset(bag,0,sizeof(bag));
14         for(int i=0;i<N;i++)scanf("%d%d",&dt[i].w,&dt[i].v);
15         for(int i=0;i<N;i++){
16             for(int j=M;j>=dt[i].w;j--){
17                 bag[j]=MAX(bag[j],bag[j-dt[i].w]+dt[i].v);
18             }
19         }
20         printf("%d\n",bag[M]);
21     }
22     return 0;
23 }
时间: 2024-10-26 22:09:58

周赛题解的相关文章

Leetcode 第174场周赛 题解

Leetcode 第174场周赛 题解 方阵中战斗力最弱的 K 行 签到题,统计一下每行的军人数量,然后设置一下排序规则即可. 时间复杂度 \(O(nlogn)\) typedef long long ll; typedef double db; #define _for(i,a,b) for(int i = (a);i < b;i ++) #define _rep(i,a,b) for(int i = (a);i > b;i --) #define INF 0x3f3f3f3f3f3f3f3

Leetcode 第175场周赛 题解(完结)

Leetcode 第175场周赛 题解 检查整数及其两倍数是否存在 数据范围小的可怜,\(O(n^2)\) 解法可行.如果范围大一点,可以先进行排序然后遍历每一个数进行二分查找,时间复杂度 \(O(nlogn)\) 代码是平方解法. typedef long long ll; typedef double db; #define _for(i,a,b) for(int i = (a);i < b;i ++) #define _rep(i,a,b) for(int i = (a);i > b;i

Leetcode 184周赛题解

前一宿没睡好,困的不行,写的有点慢.. 5380. 数组中的字符串匹配 题目描述: 给你一个字符串数组 words ,数组中的每个字符串都可以看作是一个单词.请你按 任意 顺序返回 words 中是其他单词的子字符串的所有单词.如果你可以删除 words[j] 最左侧和/或最右侧的若干字符得到 word[i] ,那么字符串 words[i] 就是 words[j] 的一个子字符串. 题解: 两次遍历,用kmp判断一下是否是字串. AC代码: class Solution { public: in

第十周周赛题解

A题: 二分题目,具体二分公式看我代码吧(ーー゛) 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #define maxa 20100 6 using namespace std; 7 int a[maxa],l[maxa],r[maxa],n; 8 bool comp(int p) 9 { 10 int x= a[1],y= p-a[1

第六周周赛题解

A题 这题贼水,直接暴力就可以了. 用个bool数组记录一下,如果某一天,当前剩下的最大的出现了的话,就输出一段. 1 #include<stdio.h> 2 int n; 3 bool vis[100010]; 4 int main() 5 { 6 scanf("%d",&n); 7 int x; 8 int now=n; 9 for(int i=1;i<=n;++i) 10 { 11 scanf("%d",&x); 12 vis

第三次周赛题解【并查集 KMP DFS BFS 快速幂】

问题 A: 一道签到题 时间限制: 2 Sec  内存限制: 128 MB 提交: 63  解决: 28 [提交][状态][讨论版] 题目描述 我想说这是一道签到题,意思就是本次测试中最水的一道,不过我这样说你真的愿意相信我吗?哈哈,题目是这样的给你一下小数,然后请告诉我分别告诉我这个小数的循环节的循环次数.循环节以及循环节长度 输入 输入包括多组测试数据每组测试数据1行,包括一个小数,小数的长度不超过200,小数大于0小于100 输出 分别输出这个小数的循环节的长度.循环节以及循环次数,中间以

ACM团队周赛题解(2)

拉了CF583和CF486的两套div2题目 还是先贴宏定义部分 #define MAXN 1000000+5#define MOD 1000000007#define PI (acos(-1.0))#define EPS 1e-6#define MMT(s,a) memset(s, a, sizeof s)#define GO(i,a,b) for(int i = (a); i < (b); ++i)#define GOE(i,a,b) for(int i = (a); i <= (b);

ACM团队周赛题解(3)

940和822两套div.2 老规矩 #define MAXN 1000000+5#define MOD 1000000007#define PI (acos(-1.0))#define EPS 1e-6#define MMT(s,a) memset(s, a, sizeof s)#define GO(i,a,b) for(int i = (a); i < (b); ++i)#define GOE(i,a,b) for(int i = (a); i <= (b); ++i)#define OG

LeetCode 171周赛题解

1317. 将整数转换为两个无零整数的和 1 class Solution { 2 public: 3 bool check(int n){ 4 while(n){ 5 if(n%10==0){ 6 return false; 7 } 8 n=n/10; 9 } 10 return true; 11 } 12 vector<int> getNoZeroIntegers(int n) { 13 for(int i=1;i<=n;i++){ 14 if(check(i)&&c