Codeforces#362
A题
题意:给定一串数列,t,t+s,t+s+1,t+2s,t+2s+1......问某一个数是否是数列当中的
题意:只需判断(x-t)与(x-t-1)能否整除s即可,注意起始时的判断
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <bitset>
- #include <cmath>
- #include <queue>
- #include <stack>
- using namespace std;
- int t,s,x;
- int main()
- {
- while(cin>>t>>s>>x)
- {
- int flag=;
- if(x<=t+){
- if(x==t)
- flag=;
- }else{
- if((x-t)%s==){
- flag=;
- }else if((x-t-)%s==){
- flag=;
- }
- }
- if(flag) cout<<"YES"<<endl;
- else cout<<"NO"<<endl;
- }
- return ;
- }
B题
题意:给定科学技术法,求出这个数
分析:直接模拟即可
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <bitset>
- #include <cmath>
- #include <queue>
- #include <stack>
- using namespace std;
- string s;
- int main()
- {
- while(cin>>s)
- {
- int k;
- for(int i=;i<s.length();i++){
- if(s[i]=='e'){
- k=i; break;
- }
- }
- int sum=;
- for(int i=k+;i<s.length()-;i++){
- sum+=(s[i]-'');
- sum*=;
- }
- sum+=s[s.length()-]-'';
- // cout<<sum<<endl;
- int len=k-;
- int h=sum;
- int cnt=;
- if(sum==)
- cnt=;
- while(h){
- h/=;
- cnt++;
- }
- // cout<<cnt<<endl;
- // cout<<len<<endl;
- if(len==&&s[]==''&&sum==)
- {
- cout<<s[]<<endl;
- continue;
- }
- if(sum<len){
- cout<<s[];
- for(int i=;i<sum+;i++)
- cout<<s[i];
- cout<<".";
- for(int i=sum+;i<s.length()-cnt-;i++)
- cout<<s[i];
- cout<<endl;
- }else if(sum==len){
- cout<<s[];
- for(int i=;i<s.length()-cnt-;i++)
- cout<<s[i];
- cout<<endl;
- }else{
- cout<<s[];
- for(int i=;i<s.length()-cnt-;i++)
- cout<<s[i];
- for(int i=;i<sum-len;i++)
- cout<<"";
- cout<<endl;
- }
- }
- return ;
- }
C题:
题意:给定每条边上的权值,求树上两点之间的距离
分析:对于两个结点x和y。我们记录下x到y每一步的权值,直到x与y的值相等为止,注意数据范围比较大,用map记录比较好
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <bitset>
- #include <cmath>
- #include <queue>
- #include <stack>
- using namespace std;
- map<long long ,long long> mp;
- int main()
- {
- int q;
- cin>>q;
- while(q--)
- {
- int num;
- cin>>num;
- if(num==)
- {
- long long x,y,cost;
- cin>>x>>y>>cost;
- while(x!=y)
- {
- if(x>y)
- {
- mp[x]+=cost;
- x/=;
- }else{
- mp[y]+=cost;
- y/=;
- }
- }
- }
- else
- {
- long long x,y;
- cin>>x>>y;
- long long res=;
- while(x!=y)
- {
- if(x>y)
- {
- res+=mp[x];
- x/=;
- }else
- {
- res+=mp[y];
- y/=;
- }
- }
- cout<<res<<endl;
- }
- }
- return ;
- }
Codeforces#362的更多相关文章
- CodeForces #362 div2 B. Barnicle
题目链接: B. Barnicle 题意:给出科学计数法 转化成十进制的整数或小数 并输出. 思路:暑假训练赛见过了,当时大腿A掉了,并表示是道水题. 刷CF再次遇见,毫不留情WA了几次.比如: 0. ...
- Codeforces Round #362 (Div. 2) C. Lorenzo Von Matterhorn (类似LCA)
题目链接:http://codeforces.com/problemset/problem/697/D 给你一个有规则的二叉树,大概有1e18个点. 有两种操作:1操作是将u到v上的路径加上w,2操作 ...
- #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 ...
- 【转载】【树形DP】【数学期望】Codeforces Round #362 (Div. 2) D.Puzzles
期望计算的套路: 1.定义:算出所有测试值的和,除以测试次数. 2.定义:算出所有值出现的概率与其乘积之和. 3.用前一步的期望,加上两者的期望距离,递推出来. 题意: 一个树,dfs遍历子树的顺序是 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #362
A - Pineapple Incident #pragma comment(linker, "/STACK:102c000000,102c000000") #include &l ...
- Codeforces Round #362(Div1) D Legen...(AC自动机+矩阵快速幂)
题目大意: 给定一些开心串,每个串有一个开心值,构造一个串,每包含一次开心串就会获得一个开心值,求最大获得多少开心值. 题解: 首先先建立AC自动机.(建立fail指针的时候,对val要进行累加) 然 ...
随机推荐
- 超棒的自定义超酷滚动条jQuery插件 - Perfect Scrollbar
可能大家厌倦了千篇一律的页面滚动条,如果你希望能够设计出与众不同的页面UI设计的话,Perfect ScrollBar可能就是你寻找的解决方案. 这个滚动条来自于一个个人项目,一个简单但是非常棒的滚动 ...
- linux的学习系列 9--网络通信
ping 命令 ping 命令会向网络上的主机发送应答请求,根据响应信息可以判断远程主机是否可用. ping 命令的语法: $ping hostname or ip-address 如果网络畅通,很快 ...
- oracle中的常用函数1-------decode方法
DECODE函数是ORACLE PL/SQL是功能强大的函数之一,目前还只有ORACLE公司的SQL提供了此函数,其他数据库厂商的SQL实现还没有此功能.DECODE有什么用途呢? 先构造一个例子,假 ...
- 为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
在Android硬件抽象层(HAL)概要介绍和学习计划一文中,我们简要介绍了在Android系统为为硬件编写驱动程序的方法.简单来说,硬件驱动程序一方面分布在Linux内核中,另一方面分布在用户空间的 ...
- mysql 入门 基本命令
MYSQL入门学习之一:基本操作 1.登录数据库 www.2cto.com 命令:mysql -u username –p (mysql -h主机地址 -u用户名 -p用户密码) ...
- Python实现删除目录下相同文件
让我们来分析一下这个问题:首先,文件个数非常多,手工查找是不现实的,再说,单凭我们肉眼,在几千张图片或文件里面找到完全相同的难度也是很大的.所以要用程序实现.那么用程序怎么实现呢?根据什么判断两个文件 ...
- 将所需要的图标排成一列组成一张图片,方便管理。li的妙用
我在做一个网站的header 但是视频教学里面将电话图标,微信图标,以及每一个英文字母右边的小点拼成一副图. (图片的名字是top_ioc.png)拼成的整个图片作为li的背景.通过移动就可以分别将每 ...
- 【从汉字中提取数字】不用公式,不用VBA,如此简单的方法你是否用过?
转自:http://huaban.com/pins/19664410 具体操作过程请看附图动画:
- 剑指offer 栈的压入弹出 顺序
判断: 如果下一个弹出的数字刚好是栈顶元素,那么直接弹出 如果下一个弹出的数字不在栈顶,我们要把压栈序列中,还没有入栈的数字压入辅助栈,知道把下一个需要弹出的数字压入栈顶 如果所有的数字都入栈,但是仍 ...
- Linux 部署 Tomcat和JDK
一:安装jdk下载将jdk加压后放到/usr/local目录下: [root@master ~]#chmod 755 jdk-6u5-linux-x64.bin [root@master ~]# ./ ...