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要进行累加) 然 ...
随机推荐
- HALF<水题>
题意: 找出n/d=0.5的所有数.输入:test,x(代表n的位数,1<=x<=4).并且n和d的每一个位数不能有重复,也不能是0. 输入: 1 1 输出: the form 1/2 = ...
- 函数求值一<找规律>
函数求值 题意: 定义函数g(n)为n最大的奇数因子.求f(n)=g(1)+g(2)+g(3)+-+g(n).1<=n<=10^8; 思路: 首先明白暴力没法过.问题是如何求解,二分.知道 ...
- Keychain 浅析
什么是Keychain? 根据苹果的介绍,iOS设备中的Keychain是一个安全的存储容器,可以用来为不同应用保存敏感信息比如用户名,密码,网络密码,认证令牌.苹果自己用keychain来保存Wi- ...
- shell 分词
######################################################################### # File Name: hello.sh # Au ...
- scala模式匹配与样例类
样本类:添加了case的类便是样本类.这种修饰符可以让Scala编译器自动为这个类添加一些语法上的便捷设定.如下: 1.添加与类名一致的工厂方法.也就是说,可以写成Var("x") ...
- Problem A: 小火山的跳子游戏 多校训练2(小火山专场)(周期)
题目链接:http://acm.zzuli.edu.cn/zzuliacm/problem.php?cid=1158&pid=0 zzuli 1905 题意:如果k=1的话是1,2,3,4. ...
- opencv mat 转灰度图
Imgproc.cvtColor(sshotmat, sshotmatgray, Imgproc.COLOR_BGR2GRAY); 更多参数看 public class Imgproc { priv ...
- Django之路:QuerySet API,后台和表单
一.Django QuerySet API Django模型中我们学习了一些基本的创建和查询.这里专门讲以下数据库接口相关的接口(QuerySet API),当然你也可以选择暂时跳过这节.如果以后用到 ...
- USER-AGENT是什么
USER-AGENT是什么? USER-AGENT:记录请求所来自的浏览器. User-Agent分析网站 http://www.useragentstring.com/ 通过解析User-Agent ...
- sql视图
什么是视图 大家都知道,我们国家现在“神七”上天了.从美国的月球登月开始,人类上天不再是神话.听说,在美国,你只要出几十万美元,您就可以上一次月球进行太空旅行,所以,我们相信:在不久的将来,上天旅行将 ...