在这里放几道Steps里的题目把。

find your present (2)

Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/1024 K (Java/Others)
Total Submission(s): 4570 Accepted Submission(s): 1343
Problem Description
In the new year party, everybody will get a "special present".Now
it's your turn to get your special present, a lot of presents now
putting on the desk, and only one of them will be yours.Each present has
a card number on it, and your present's card number will be the one
that different from all the others, and you can assume that only one
number appear odd times.For example, there are 5 present, and their card
numbers are 1, 2, 3, 2, 1.so your present will be the one with the card
number of 3, because 3 is the number that different from all the
others.
 

Input
The input file will consist of several cases.
Each case will
be presented by an integer n (1<=n<1000000, and n is odd) at
first. Following that, n positive integers will be given in a line, all
integers will smaller than 2^31. These numbers indicate the card numbers
of the presents.n = 0 ends the input.
 

Output
For each case, output an integer in a line, which is the card number of your present.
 

Sample Input
5
1 1 3 2 2
3
1 2 1
0
 

Sample Output
3
2
Hint

Hint

use scanf to avoid Time Limit Exceeded

在使用桶排序、每输入一次往上遍历的方法后依然Runtime Error (STACK_OVERFLOW)

于是使用“异或”进行运算

解题思路:

 比如   3^5,   3=011,5=101,两数按位异或后为110,即6。
偶数次出现的异或结果为0 基数次结果为1
然后 异或满足交换率。
再举一个例子。
如 数据 1 2 3 2 1
先让result=0
那么可以看成是 result^1^2^3^2^1
交换律 result^1^1^2^2^3
很明显 1^1 和 2^2 都为 0
所以最后得 result^3 =0^3 =3(二进制 101)
AC代码:
 #include <stdio.h>
#include <string.h>
int main()
{
int n,res,i,j;
int x;
while(scanf("%d",&n)!=EOF)
{
if(n==)
break;
res=;
for(i=;i<n;i++)
{
scanf("%d",&x);
res=res^x;
}
printf("%d\n",res);
}
return ;
}

排序

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3499 Accepted Submission(s): 1008
Problem Description
输入一行数字,如果我们把这行数字中的‘5’都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以‘0’开头,这些头部的‘0’应该被忽略掉,除非这个整数就是由若干个‘0’组成的,这时这个整数就是0)。

你的任务是:对这些分割得到的整数,依从小到大的顺序排序输出。

 

Input
输入包含多组测试用例,每组输入数据只有一行数字(数字之间没有空格),这行数字的长度不大于1000。

输入数据保证:分割得到的非负整数不会大于100000000;输入数据不可能全由‘5’组成。

 

Output
对于每个测试用例,输出分割得到的整数排序的结果,相邻的两个整数之间用一个空格分开,每组输出占一行。
 

Sample Input
0051231232050775
 

Sample Output
0 77 12312320
注意事项: 如果是005123123205077555555555
      输出也是 0 77 12312320
如果此处不特殊考虑容易WA
AC代码:
 #include <stdio.h>
#include <string.h>
int main()
{
int ti,k,i,j,len,tmp;
int a[];
char n[];
while(gets(n))
{
k=;
ti=;
tmp=;
len=strlen(n);
for(i=len-;i>=;i--)
{
// printf("%d tmp:%d\n",n[i]-'0',tmp);
if(i==len-&&n[i]=='')
continue;
else if(n[i]=='')
{
if(n[i+]=='')
continue;
a[k]=tmp;
k++;
ti=;
tmp=;
}
else if(i==&&n[i]!='')
{
tmp+=ti*(n[i]-'');
ti*=;
a[k]=tmp;
k++;
ti=;
tmp=;
}
else
{
tmp+=ti*(n[i]-'');
ti*=;
}
}
for(i=;i<k;i++)
{
for(j=k-;j>=i;j--)
{
if(a[j]<a[j-])
{
tmp=a[j];a[j]=a[j-];a[j-]=tmp;
}
}
}
for(i=;i<k;i++)
{
if(i<k-)
printf("%d ",a[i]);
else
printf("%d\n",a[i]);
}
}
return ;
}

排名

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3051 Accepted Submission(s): 991
Problem Description
今天的上机考试虽然有实时的Ranklist,但上面的排名只是根据完成的题数排序,没有考虑
每题的分值,所以并不是最后的排名。给定录取分数线,请你写程序找出最后通过分数线的
考生,并将他们的成绩按降序打印。
 

Input
测试输入包含若干场考试的信息。每场考试信息的第1行给出考生人数N ( 0 < N
< 1000 )、考题数M ( 0 < M < = 10 )、分数线(正整数)G;第2行排序给出第1题至第M题的正整数分值;以下N行,每行给出一
名考生的准考证号(长度不超过20的字符串)、该生解决的题目总数m、以及这m道题的题号
(题目号由1到M)。
当读入的考生人数为0时,输入结束,该场考试不予处理。
 

Output
对每场考试,首先在第1行输出不低于分数线的考生人数n,随后n行按分数从高
到低输出上线考生的考号与分数,其间用1空格分隔。若有多名考生分数相同,则按他们考
号的升序输出。
 

Sample Input
4 5 25
10 10 12 13 15
CS004 3 5 1 3
CS003 5 2 4 1 3 5
CS002 2 1 2
CS001 3 2 3 5
1 2 40
10 30
CS001 1 2
2 3 20
10 10 10
CS000000000000000001 0
CS000000000000000002 2 1 2
0
 

Sample Output
3
CS003 60
CS001 37
CS004 37
0
1
CS000000000000000002 20
Hint
 写这题,QAQ,第一次同时两个对象进行排序
AC代码:
 #include <stdio.h>
#include <string.h>
struct stu
{
char n[];
int sum;
int a[];
int score;
int flag;
}a[],tmp;
int main()
{
int n,m,g,i,j,w,x,k;
int b[];
while(scanf("%d",&n)!=EOF)
{
k=;
if(n==)
break;
scanf("%d %d",&m,&g);
for(i=;i<m;i++)
scanf("%d",&b[i]);
for(i=;i<n;i++)
{
scanf("%s %d",a[i].n,&a[i].sum);
a[i].score=;
for(j=;j<a[i].sum;j++)
{
scanf("%d",&a[i].a[j]);
a[i].score+=b[a[i].a[j]-];
}
if(a[i].score>=g)
k++;
}
for(i=;i<n;i++)
{
for(j=n-;j>=i;j--)
{
if(a[j].score>a[j-].score)
{
tmp=a[j];a[j]=a[j-];a[j-]=tmp;
}
else if(a[j].score==a[j-].score)
{
if(strcmp(a[j].n,a[j-].n)<)
{
tmp=a[j];a[j]=a[j-];a[j-]=tmp;
}
}
}
}
printf("%d\n",k);
for(i=;i<k;i++)
printf("%s %d\n",a[i].n,a[i].score);
}
return ;
}

Wooden Sticks

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1981 Accepted Submission(s): 779
Problem Description
There is a pile of n wooden sticks. The length and weight of each
stick are known in advance. The sticks are to be processed by a
woodworking machine in one by one fashion. It needs some time, called
setup time, for the machine to prepare processing a stick. The setup
times are associated with cleaning operations and changing tools and
shapes in the machine. The setup times of the woodworking machine are
given as follows:

(a) The setup time for the first wooden stick is 1 minute.
(b)
Right after processing a stick of length l and weight w , the machine
will need no setup time for a stick of length l' and weight w' if
l<=l' and w<=w'. Otherwise, it will need 1 minute for setup.

You
are to find the minimum setup time to process a given pile of n wooden
sticks. For example, if you have five sticks whose pairs of length and
weight are (4,9), (5,2), (2,1), (3,5), and (1,4), then the minimum setup
time should be 2 minutes since there is a sequence of pairs (1,4),
(3,5), (4,9), (2,1), (5,2).

 

Input
The input consists of T test cases. The number of test cases (T)
is given in the first line of the input file. Each test case consists of
two lines: The first line has an integer n , 1<=n<=5000, that
represents the number of wooden sticks in the test case, and the second
line contains n 2 positive integers l1, w1, l2, w2, ..., ln, wn, each of
magnitude at most 10000 , where li and wi are the length and weight of
the i th wooden stick, respectively. The 2n integers are delimited by
one or more spaces.
 

Output
The output should contain the minimum setup time in minutes, one per line.
 

Sample Input
3
5
4 9 5 2 2 1 3 5 1 4
3
2 2 1 1 2 2
3
1 3 2 2 3 1
 

Sample Output
2
1
3
 这是我AC的第一道贪心题,一开始差不多写出来的时候自己测试却发现有问题,一直想不到。
后来才发现原来是是忘记对FLAG数组初始化导致后面的判断会直接跳过T^T
好吧,直接上AC代码:
 
 // 贪心算法---先排序---后选择第一个没有用过的木头一次向后找,用掉所有可以用掉的木头,然后返回第一个没用过的木头继续找
#include <stdio.h>
#include <string.h>
struct sticks
{
int a;
int b;
}a[],tmp;
int main()
{
int i,j,t,n,st,count;
int flag[],ti;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
for(i=;i<;i++)
flag[i]=;//对flag数组清零
scanf("%d",&n);
for(i=;i<n;i++)
scanf("%d%d",&a[i].a,&a[i].b);
for(i=;i<n;i++)//按照长度从小到大排序,若长度相同按照重量递增排序
{
for(j=n-;j>=i;j--)
{
if(a[j].a<a[j-].a || a[j].a==a[j-].a && a[j].b<a[j-].b)
{
tmp=a[j];a[j]=a[j-];a[j-]=tmp;
}
}
}
st=; //记录第一个没有用过的木头,st为其下标
count=;
flag[]=;//从a[0]开始,故对a[0]元素作使用标记
while(st<n)
{
++count;//一次安装耗时
for(i=st+,j=st,ti=;i<n;++i)//j为当前操作木棒下标,i为下一待操作木棒下标,ti为有无尚未使用木棒的标识符号
{
if(flag[i])//检查下标为i的目标是否已被使用
continue;
if(a[j].a<=a[i].a&&a[j].b<=a[i].b)
{
flag[i]=;//赋予使用过木棒flag标示符为1
j=i;//当前木棒下标即为i
}
else
{
if(ti)//如果ti!=0
{
st=i;//只记录第一个没用过的木头
ti=;//表明有尚未使用过的木棒
}
}
}
if(ti)//遍历完所有木棒,但仍找不到没使用过的木棒,ti==1,说明都用过了,跳出循环
break;
}
printf("%d\n",count);
}
}
return ;
}

Crixalis's Equipment

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2426 Accepted Submission(s): 721
Problem Description
Crixalis
- Sand King used to be a giant scorpion(蝎子) in the deserts of
Kalimdor. Though he's a guardian of Lich King now, he keeps the living
habit of a scorpion like living underground and digging holes.

Someday
Crixalis decides to move to another nice place and build a new house
for himself (Actually it's just a new hole). As he collected a lot of
equipment, he needs to dig a hole beside his new house to store them.
This hole has a volume of V units, and Crixalis has N equipment, each of
them needs Ai units of space. When dragging his equipment into the
hole, Crixalis finds that he needs more space to ensure everything is
placed well. Actually, the ith equipment needs Bi units of space during
the moving. More precisely Crixalis can not move equipment into the hole
unless there are Bi units of space left. After it moved in, the volume
of the hole will decrease by Ai. Crixalis wonders if he can move all his
equipment into the new hole and he turns to you for help.

 

Input
The first line contains an integer T, indicating the number of
test cases. Then follows T cases, each one contains N + 1 lines. The
first line contains 2 integers: V, volume of a hole and N, number of
equipment respectively. The next N lines contain N pairs of integers: Ai
and Bi.
0<T<= 10, 0<V<10000, 0<N<1000, 0 <Ai< V, Ai <= Bi < 1000.
 

Output
For each case output "Yes" if Crixalis can move all his equipment into the new hole or else output "No".
 

Sample Input
2

20 3
10 20
3 10
1 7 10 2
1 10
2 11
 

Sample Output
Yes
No

写这题的时候丝毫没感觉这提是贪心题,但是WA了几次还是没有AC的情况下

反过来想,要把n件物品全部搬到洞里,需要的最小空间是多少?

那么就很明显看出来这是一道贪心题

解题思路:

假设有物品 10  20 (thing 1)

       1   7 (thing 2)

先搬物品1后搬物品2需要的最小空间是:max(20,10+7)=20

先搬物品2后搬物品1需要的最小空间是:max(7,1+20)=21

那么我们选择的会是 先搬物品1后搬物品2

物品1和物品2的差别在于(BI-AI)的值

故因此的出:

贪心策略是 先搬差值大的,相等就随意!!

AC代码:

 #include <stdio.h>
#include <string.h>
struct sc
{
int a,b,c;
}a[],tmp;
int main()
{
int t,i,j,v,n;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
scanf("%d%d",&v,&n);
for(i=;i<n;i++)
{
scanf("%d%d",&a[i].a,&a[i].b);
a[i].c=a[i].b-a[i].a;
}
for(i=;i<n;i++)
{
for(j=n-;j>=i;j--)
{
if(a[j].c>a[j-].c)
{
tmp=a[j];a[j]=a[j-];a[j-]=tmp;
}
}
}
for(i=;i<n;i++)
{
if(a[i].b>v)
{
printf("No\n");
break;
}
v-=a[i].a;
if(i==n-)
printf("Yes\n");
}
}
}
return ;
}

Leftmost Digit

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2142 Accepted Submission(s): 939
 
Problem Description
Given a positive integer N, you should output the leftmost digit of N^N.
 
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
 
Output
For each test case, you should output the leftmost digit of N^N.
 
Sample Input
2
3
4
 
Sample Output
2
2
Hint

In the first case, 3 * 3 * 3 = 27, so the leftmost digit is 2. In the second case, 4 * 4 * 4 * 4 = 256, so the leftmost digit is 2.

对一个数num可写为 num=10n + a, 即科学计数法,使a的整数部分即为num的最高位数字
 
numnum=10n + a 这里的n与上面的n不等
 
两边取对数: num*lg(num) = n + lg(a);
 
因为a<10,所以0<lg(a)<1
 
令x=n+lg(a); 则n为x的整数部分,lg(a)为x的小数部分
 
又x=num*lg(num);
a=10(x-n) = 10(x-int(x)))
 
再取a的整数部分即得num的最高位
AC代码:
 #include<stdio.h>
#include<math.h>
int main()
{
int t,a,n;
double x;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
scanf("%d",&n);
x=n*log10(n*1.00000);
x-=(__int64)x;
a=pow(10.0000,x);
printf("%d\n",a);
}
}
return ;
}

HDOJ-ACM Steps的更多相关文章

  1. HDOJ acm steps 3.1.1

    (都是递推求值,呵呵,好开心- - ) 今天又是在自习室通宵(文明玩的停不下来了) 游戏玩完想想该水题了,于是打开了HDOJ的ACM STEPS(这是个好东西,就像他的名字,一步步来的) 2.3.x貌 ...

  2. ACM STEPS——Chapter Two——Section One

    数学题小关,做得很悲剧,有几道题要查数学书... 记下几道有价值的题吧 The area(hdoj 1071) http://acm.hdu.edu.cn/showproblem.php?pid=10 ...

  3. hdu acm steps Big Event in HDU

    上网搜了一下这道题的解法,主要有两个方法,一种是采用母函数的方法,一种是采用0/1背包的方法. 先说一下母函数,即生成函数,做个比喻,母函数就是一个多项式前面的系数的一个整体的集合,而子函数就是这个多 ...

  4. hdu ACM Steps Section 1 花式A+B 输入输出格式

    acm与oi很大的一个不同就是在输入格式上.oi往往是单组数据,而acm往往是多组数据,而且题目对数据格式往往各有要求,这8道a+b(吐槽..)涉及到了大量的常用的输入输出格式.https://wen ...

  5. ACM Steps 2.1.8

    小数化分数2   Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)  Total Sub ...

  6. ACM Steps 2.1.7

    Leftmost Digit   Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)  T ...

  7. ACM Steps 2.1.4

    Largest prime factor   Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...

  8. 2015寒假ACM训练计划

    1月26号至3月4号 每天给自己一个计划.做有意义的事情,不要浪费时间. 8:00——11:30 acm训练 11:30——13:00 午休 13:00——17:30  acm训练 17:30——18 ...

  9. HDOJ/HDU 1161 Eddy's mistakes(大写字母转换成小写字母)

    Problem Description Eddy usually writes articles ,but he likes mixing the English letter uses, for e ...

  10. hdu 1087 动态规划之最长上升子序列

    http://acm.hdu.edu.cn/showproblem.php?pid=1087 Online Judge Online Exercise Online Teaching Online C ...

随机推荐

  1. PHP搭建简单暴力的mvc

    对于一个web系统来说,我们使用mvc很必要, 给我们带来的是清晰的结构,易运维,易扩展, mvc 我对其的理解应该叫mxvc, 多了一个x , 这个x代表什么,x可以理解为 relay,proxy, ...

  2. Android 动画系列

    Android种最常用的动画: ~1~Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转.平移.放缩和渐变) Tweene Animations 主要类: Animation   ...

  3. Javascript 匀速运动停止条件——逐行分析代码,让你轻松了解运动的原理

    我们先来看下之前的匀速运动的代码,修改了速度speed后会出现怎么样的一个bug.这里加了两个标杆用于测试 <style type="text/css"> #div1 ...

  4. js previousSibling兼容使用方法

    使用previousSibling的时候发现当前元素跟上一个元素之间有空格就不获取不到对象, 查资料才知道除了ie外js的previousSibling获取的对象包括空格! 兼容方法如下: funct ...

  5. HTML5兼容IE各版本的写法

    IE下判断IE版本的语句 <!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见   <!--[if lte IE 7]> < ...

  6. lua学习笔记1

    lua中调用c的函数 #include <stdio.h> #include <string.h> #ifdef __cplusplus extern "C" ...

  7. FLAG_ACTIVITY_NEW_TASK和SingleInstance的设计思路(多task的应用)

    这部分的想法都是基于以下两点: 1.Activity可能被复用,可能是复用Activity的功能,还可能是复用Activity的状态: 2.Task的作用:target,同一个task中的Activi ...

  8. Linux----给一个普通用户root权限

    问题说明:linux可以通过useradd创建用户.那有没有想过.我们创建的用户怎么样才可以使它得到全部的root权限呢? 解决办法: 1.这是一个可以打80分的办法.就是编辑/etc/sudoers ...

  9. 这才是正确删除 office 的方式

    https://support.office.com/zh-cn/article/%E9%80%9A%E8%BF%87%E5%9C%A8%E9%87%8D%E6%96%B0%E5%AE%89%E8%A ...

  10. mysql timestamp 值不合法问题

    Create Table: CREATE TABLE `RecruitmentDesc` ( `sn` int(11) NOT NULL AUTO_INCREMENT COMMENT '编号(自增字段 ...