A题

题意:给定一串数列,t,t+s,t+s+1,t+2s,t+2s+1......问某一个数是否是数列当中的

题意:只需判断(x-t)与(x-t-1)能否整除s即可,注意起始时的判断

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <string>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <set>
  8. #include <map>
  9. #include <bitset>
  10. #include <cmath>
  11. #include <queue>
  12. #include <stack>
  13. using namespace std;
  14. int t,s,x;
  15. int main()
  16. {
  17. while(cin>>t>>s>>x)
  18. {
  19. int flag=;
  20. if(x<=t+){
  21. if(x==t)
  22. flag=;
  23. }else{
  24. if((x-t)%s==){
  25. flag=;
  26. }else if((x-t-)%s==){
  27. flag=;
  28. }
  29. }
  30. if(flag) cout<<"YES"<<endl;
  31. else cout<<"NO"<<endl;
  32. }
  33. return ;
  34. }

B题

题意:给定科学技术法,求出这个数

分析:直接模拟即可

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <string>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <set>
  8. #include <map>
  9. #include <bitset>
  10. #include <cmath>
  11. #include <queue>
  12. #include <stack>
  13. using namespace std;
  14. string s;
  15. int main()
  16. {
  17. while(cin>>s)
  18. {
  19. int k;
  20. for(int i=;i<s.length();i++){
  21. if(s[i]=='e'){
  22. k=i; break;
  23. }
  24. }
  25. int sum=;
  26. for(int i=k+;i<s.length()-;i++){
  27. sum+=(s[i]-'');
  28. sum*=;
  29. }
  30. sum+=s[s.length()-]-'';
  31. // cout<<sum<<endl;
  32. int len=k-;
  33. int h=sum;
  34. int cnt=;
  35. if(sum==)
  36. cnt=;
  37. while(h){
  38. h/=;
  39. cnt++;
  40. }
  41. // cout<<cnt<<endl;
  42. // cout<<len<<endl;
  43. if(len==&&s[]==''&&sum==)
  44. {
  45. cout<<s[]<<endl;
  46. continue;
  47. }
  48. if(sum<len){
  49. cout<<s[];
  50. for(int i=;i<sum+;i++)
  51. cout<<s[i];
  52. cout<<".";
  53. for(int i=sum+;i<s.length()-cnt-;i++)
  54. cout<<s[i];
  55. cout<<endl;
  56. }else if(sum==len){
  57. cout<<s[];
  58. for(int i=;i<s.length()-cnt-;i++)
  59. cout<<s[i];
  60. cout<<endl;
  61. }else{
  62. cout<<s[];
  63. for(int i=;i<s.length()-cnt-;i++)
  64. cout<<s[i];
  65. for(int i=;i<sum-len;i++)
  66. cout<<"";
  67. cout<<endl;
  68. }
  69. }
  70. return ;
  71. }

C题:

题意:给定每条边上的权值,求树上两点之间的距离

分析:对于两个结点x和y。我们记录下x到y每一步的权值,直到x与y的值相等为止,注意数据范围比较大,用map记录比较好

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <string>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <set>
  8. #include <map>
  9. #include <bitset>
  10. #include <cmath>
  11. #include <queue>
  12. #include <stack>
  13. using namespace std;
  14. map<long long ,long long> mp;
  15. int main()
  16. {
  17. int q;
  18. cin>>q;
  19. while(q--)
  20. {
  21. int num;
  22. cin>>num;
  23. if(num==)
  24. {
  25. long long x,y,cost;
  26. cin>>x>>y>>cost;
  27. while(x!=y)
  28. {
  29. if(x>y)
  30. {
  31. mp[x]+=cost;
  32. x/=;
  33. }else{
  34. mp[y]+=cost;
  35. y/=;
  36. }
  37. }
  38. }
  39. else
  40. {
  41. long long x,y;
  42. cin>>x>>y;
  43. long long res=;
  44. while(x!=y)
  45. {
  46. if(x>y)
  47. {
  48. res+=mp[x];
  49. x/=;
  50. }else
  51. {
  52. res+=mp[y];
  53. y/=;
  54. }
  55. }
  56. cout<<res<<endl;
  57. }
  58. }
  59. return ;
  60. }

Codeforces#362的更多相关文章

  1. CodeForces #362 div2 B. Barnicle

    题目链接: B. Barnicle 题意:给出科学计数法 转化成十进制的整数或小数 并输出. 思路:暑假训练赛见过了,当时大腿A掉了,并表示是道水题. 刷CF再次遇见,毫不留情WA了几次.比如: 0. ...

  2. Codeforces Round #362 (Div. 2) C. Lorenzo Von Matterhorn (类似LCA)

    题目链接:http://codeforces.com/problemset/problem/697/D 给你一个有规则的二叉树,大概有1e18个点. 有两种操作:1操作是将u到v上的路径加上w,2操作 ...

  3. #map+LCA# Codeforces Round #362 (Div. 2)-C. Lorenzo Von Matterhorn

    2018-03-16 http://codeforces.com/problemset/problem/697/C C. Lorenzo Von Matterhorn time limit per t ...

  4. 【转载】【树形DP】【数学期望】Codeforces Round #362 (Div. 2) D.Puzzles

    期望计算的套路: 1.定义:算出所有测试值的和,除以测试次数. 2.定义:算出所有值出现的概率与其乘积之和. 3.用前一步的期望,加上两者的期望距离,递推出来. 题意: 一个树,dfs遍历子树的顺序是 ...

  5. Codeforces Round #362 (Div. 2) A.B.C

    A. Pineapple Incident time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. Codeforces Round #362 (Div. 2)->B. Barnicle

    B. Barnicle time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  7. Codeforces Round #362 (Div. 2)->A. Pineapple Incident

    A. Pineapple Incident time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. Codeforces Round #362

    A - Pineapple Incident #pragma comment(linker, "/STACK:102c000000,102c000000") #include &l ...

  9. Codeforces Round #362(Div1) D Legen...(AC自动机+矩阵快速幂)

    题目大意: 给定一些开心串,每个串有一个开心值,构造一个串,每包含一次开心串就会获得一个开心值,求最大获得多少开心值. 题解: 首先先建立AC自动机.(建立fail指针的时候,对val要进行累加) 然 ...

随机推荐

  1. 超棒的自定义超酷滚动条jQuery插件 - Perfect Scrollbar

    可能大家厌倦了千篇一律的页面滚动条,如果你希望能够设计出与众不同的页面UI设计的话,Perfect ScrollBar可能就是你寻找的解决方案. 这个滚动条来自于一个个人项目,一个简单但是非常棒的滚动 ...

  2. linux的学习系列 9--网络通信

    ping 命令 ping 命令会向网络上的主机发送应答请求,根据响应信息可以判断远程主机是否可用. ping 命令的语法: $ping hostname or ip-address 如果网络畅通,很快 ...

  3. oracle中的常用函数1-------decode方法

    DECODE函数是ORACLE PL/SQL是功能强大的函数之一,目前还只有ORACLE公司的SQL提供了此函数,其他数据库厂商的SQL实现还没有此功能.DECODE有什么用途呢? 先构造一个例子,假 ...

  4. 为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序

    在Android硬件抽象层(HAL)概要介绍和学习计划一文中,我们简要介绍了在Android系统为为硬件编写驱动程序的方法.简单来说,硬件驱动程序一方面分布在Linux内核中,另一方面分布在用户空间的 ...

  5. mysql 入门 基本命令

    MYSQL入门学习之一:基本操作  1.登录数据库    www.2cto.com     命令:mysql -u username –p (mysql -h主机地址 -u用户名 -p用户密码)   ...

  6. Python实现删除目录下相同文件

    让我们来分析一下这个问题:首先,文件个数非常多,手工查找是不现实的,再说,单凭我们肉眼,在几千张图片或文件里面找到完全相同的难度也是很大的.所以要用程序实现.那么用程序怎么实现呢?根据什么判断两个文件 ...

  7. 将所需要的图标排成一列组成一张图片,方便管理。li的妙用

    我在做一个网站的header 但是视频教学里面将电话图标,微信图标,以及每一个英文字母右边的小点拼成一副图. (图片的名字是top_ioc.png)拼成的整个图片作为li的背景.通过移动就可以分别将每 ...

  8. 【从汉字中提取数字】不用公式,不用VBA,如此简单的方法你是否用过?

    转自:http://huaban.com/pins/19664410 具体操作过程请看附图动画:

  9. 剑指offer 栈的压入弹出 顺序

    判断: 如果下一个弹出的数字刚好是栈顶元素,那么直接弹出 如果下一个弹出的数字不在栈顶,我们要把压栈序列中,还没有入栈的数字压入辅助栈,知道把下一个需要弹出的数字压入栈顶 如果所有的数字都入栈,但是仍 ...

  10. Linux 部署 Tomcat和JDK

    一:安装jdk下载将jdk加压后放到/usr/local目录下: [root@master ~]#chmod 755 jdk-6u5-linux-x64.bin [root@master ~]# ./ ...