`
linest
  • 浏览: 150601 次
  • 性别: Icon_minigender_1
  • 来自: 内蒙古
社区版块
存档分类
最新评论
文章列表

ZOJ-1383 二进制找1

    博客分类:
  • acm
1383: 给一整数,输出二进制下1的位置。 The position of the least significant bit is 0 Sample Input 1 13 Sample Output 0 2 3 由于从最小端开始逆序输出,因此采用取模的方法。 由于不知道最后一位什么时候输出,因此空格放在头部判断。 #include<stdio.h> #include<iostream> using namespace std; int main() { int d; int n; int pos=0; bool ishe ...

ZOJ-1382 n=o2^p

    博客分类:
  • acm
1382:n = o2^p 其中o是奇数 1 <= n <= 10^6  给出n 求满足的o和p 简单题。因为o是奇数,所以对n一直右移移位,即除2,直到剩下奇数为止。 #include<stdio.h> #include<iostream> using namespace std; int main() { int d; int n; int p; cin>>d; for(int i=0;i<d;i++) { cin>>n; p=0; while(n%2==0) ...

ZOJ-1365 基本应用

    博客分类:
  • acm
1365:根据不同的飞行里程计算积分。 简单题,完全看懂题目就可。 #include<stdio.h> #include<iostream> #include<string.h> using namespace std; int main() { char start[100]; char end[100]; int dis; char level; int sum=0; while(1) { cin>>start; if(strcmp(start,"#")==0 ...

ZOJ-1331* a3=b3+c3+d3

    博客分类:
  • acm
1331:求a在200以内满足a的立方等于b,c,d立方和的所有解。按a升序列出。 对于相同的a可能有符合的多种组合,要求按升序列出。 思路是多重循环遍历求解。 第一次写得代码如下: #include<stdio.h> #include<string.h> #include<iostream> #include<memory.h> #include<math.h> #include<vector> #include<algorithm> using namespace std; stru ...

ZOJ-1334 进制转换

    博客分类:
  • acm
1334:给出源数 给出源数的基 和目标数的基 求目标数 目标数最长7位 右对齐显示 Sample Input 1111000 2 10   1111000 2 16 2102101  3 10 2102101 3   15 12312 4   2 1A   15 2    1234567 10 16   ABCD 16 15 Sample Output     120      78    1765     7CA   ERROR   11001 12D687    D071 思路:将源数转换成10进制,再转成目标进制 char res[8] 数组存字符串一定要记得给末尾\0 ...

ZOJ-1292 大数相加

    博客分类:
  • acm
1292:给出一组大数,可长达100位,求它们的和。 和1205很相似。区别是进制不同。1205是两个数加,本题为多个数加。 Sample Input 1 123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890 0 Sample Output 370370367037037036703703703670 思路为每个数单独贡献和值,这样就跟数的个数无关。 先不考虑进制,全加完后统一处理。 每个数的长度不同,因此存结果时先逆序比较方便。 #in ...

ZOJ-1251 平均化

    博客分类:
  • acm
1251:很多堆高低不等的砖块,每次移动一个,为了弄成等高,求最少步数。 Sample Input 6 5 2 4 1 7 5 0 Sample Output Set #1 The minimum number of moves is 5. 简单题。先求平均,凡是大于平均的部分都移走,即得结果。 #include<stdio.h> #include<iostream> using namespace std; int heap[50]; int main() { int n; int sum; int step; i ...
逆序数:在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序。 如: P 5 9 1 8 2 6 4 7 3 I 2 3 6 4 0 2 2 1 0 1前面比1大的有2个 2前面比2大的有3个 3前面比3大的有6个。。。。 1201:在permutation 和inversion之间转换。 思路:P-->I 双重循环,对每个数统计前面比它大的有几个 I-->P 双重循环。从最小的开始排起,每次从头扫描,给比它大的值留下空位。 #include<stdio.h> #include<memory.h> ...

ZOJ-1216 叠卡片

    博客分类:
  • acm
1216:多张卡片叠放在桌子边沿,问卡片最多能伸出多长。 设卡片有n张,最底层卡片伸出的部分比例为x,则未伸出占1-x. 均匀的杆密度一样可约掉。 有n-1张卡片叠在最底层上,将n-1块视为一体,重心在最底层的伸出端端点上。 以桌子角为支点  根据力矩  重量*距离  平衡 (1-x)*((1-x)/2) = x*(x/2) + (n-1)*x          1-x | x        ============ ———————— 解得x=1/2n 因此一块时 1/2 两块时     1/2+1/4 三块时     1/2+1/4+1/6 ...... #include&l ...
1205:计算两个二十进制数的和 Sample Input: 1234567890 abcdefghij 99999jjjjj 9999900001 Sample Output: bdfi02467j iiiij00000 值和字符间的转换关系 int convertToInt(char src) { if(src>='0'&&src<='9') return src-'0'; else if(src>='a'&&src<='j') return src-'a'+10; } char con ...

ZOJ-1295 字符串逆序

    博客分类:
  • acm
1295:字符串逆序输出 Sample Input 3 Frankly, I don't think we'll make much money out of this scheme. madam I'm adam Sample Output hcum ekam ll'ew kniht t'nod I ,ylknarF .emehcs siht fo tuo yenom mada m'I madam 简单题。。 借助stl库 algorithm中 reverse函数。 读取用到gets(char*) 含空白符的整行读取 getchar 读取单字符。 #include<ios ...

ZOJ-1241 勾股定理

    博客分类:
  • acm
1241:a,b直角边,c斜边 已知两边求另一边。 简单题。。 由于浮点数不宜比大小和判相等,边采用整型,结果采用浮点型。 #include<iostream> #include<stdio.h> #include<math.h> using namespace std; int main() { int a; int b; int c; double res; int n=1; while(1) { cin>>a; cin>>b; cin>>c; ...

ZOJ-1089* 组合

    博客分类:
  • acm
3年了,一直没充分利用资源,现决定勤做做,锻炼一下编程能力。 自己写的也好,参考的也罢,都是一种学习。 1089:在一串升序的数里选6个数,打印所有的选法。 生成组合问题。用1~N生成组合数,对应到读入数据的下标打印即可。 参考代码。递归方法实现。 dummy函数是对一种组合结果的处理函数。现在只是单纯打印组合结果。 根据需要改动。本题输出对应下标的结果值在其中完成。 int count=0; //用于计数 void dummy(int* a,int n){ int i; cout<<count++<<": "; for (i ...
Global site tag (gtag.js) - Google Analytics