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要进行累加) 然 ...
随机推荐
- Spring Boot 系列教程5-热部署-devtools模块
devtools模块 devtools模块,是为开发者服务的一个模块.主要的功能就是代码修改后一般在5秒之内就会自动重新加载至服务器,相当于restart成功. 原理 简单原理 在发现代码有更改之后, ...
- Android简单逐帧动画Frame的实现(三)
android之动画(三)通过AnimationDrawable控制逐帧动画 android与逐帧动画: 效果图: 当我们点击按钮时,该图片会不停的旋转,当再次点击按钮时,会停止在当前的状态. ...
- AIX创建用户
-bash-3.2# mkuser test 创建用户3004-689 User "test" exists.-bash-3.2# finge ...
- Android Studio相关的坑
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...
- 如何让Spring MVC接收的参数可以转换为java对象
场景: web.xml中增加了一个DispatcherServlet配置,并在同级目录下添加了**-servlert.xml文件,搭建起了一个spring mvc的restful访问接口. 问题描述: ...
- c# 执行js的方法
http://www.cnblogs.com/wuhuacong/archive/2010/11/08/1871866.html 为了有效阻止恶意用户的攻击,一般登录都会采用验证码方式方式处理登录,类 ...
- Mysql命令-求一列字段的总和
求和命令 mysql> select SUM(price) from order where create_time>'2016-03-12';+------------+| SUM(pr ...
- Android AudioPolicyService服务启动过程
AudioPolicyService是策略的制定者,比如什么时候打开音频接口设备.某种Stream类型的音频对应什么设备等等.而AudioFlinger则是策略的执行者,例如具体如何与音频设备通信,如 ...
- [转]JSON详解
阅读目录 JSON的两种结构 认识JSON字符串 在JS中如何使用JSON 在.NET中如何使用JSON 总结 JSON的全称是”JavaScript Object Notation”,意思是Java ...
- Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconn
使用MySQL执行update的时候报错: MySQL 在使用mysql执行update的时候,如果不是用主键当where语句,会报如下错误,使用主键用于where语句中正常. 异常内容: ...