Codeforces 903 绝对值1e19longdouble算贡献 汉明距离交换两项是否可行
A
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
const int mod = 1e9 + ;
const int gakki = + + + + 1e9;
const int N = ( << ) + ;
int main()
{
int T;
cin >> T;
while (T--)
{
int flag=;
int n;
cin >> n;
for (int i = ; i <= n / ; i++)
{
if ((n - * i) % == )
{
cout << "YES" << endl;
flag=;
break;
}
}
if(!flag)
{
cout<<"NO"<<endl;
}
} return ;
}
B
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
const int mod = 1e9 + ;
const int gakki = + + + + 1e9;
const int N = ( << ) + ;
string ans[];
int cnt = ;
int main()
{
ios_base::sync_with_stdio();
cin.tie();
int h1, a1, c1;
int h2, a2;
cin >> h1 >> a1 >> c1;
cin >> h2 >> a2;
while (h2 > )
{
if (h2 - a1 <= )
{
ans[++cnt] = "STRIKE";
h2 -= a1;
continue;
}
if (h1 - a2 <= )
{
ans[++cnt] = "HEAL";
h1 += c1-a2;
continue;
}
ans[++cnt] = "STRIKE";
h1 -= a2;
h2 -= a1;
}
cout << cnt << endl;
for (int i = ; i <= cnt; i++)
{
cout << ans[i] << endl;
}
return ;
}
C
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
const int mod = 1e9 + ;
const int gakki = + + + + 1e9;
const int N = 5e3 + ;
int vis[N];
int num[N];
int visit[N];
int main()
{
ios_base::sync_with_stdio();
cin.tie();
int n;
cin >> n;
int maxn = -;
for (int i = ; i <= n; i++)
{
cin >> num[i];
maxn = max(maxn, num[i]);
}
sort(num + , num + + n);
for (int i = ; i <= n; i++)
{
if (visit[i])
{
continue;
}
int cur = num[i];
int pre = i;
vis[pre] = ;
visit[pre] = ;
for (int j = i + ; j <= n; j++)
{
if (num[j] > cur && !visit[j])
{
visit[j] = ;
vis[pre] = ;
cur = num[j];
pre = j;
vis[pre] = ;
}
}
}
int anser = ;
for (int i = ; i <= n; i++)
{
if (vis[i])
{
anser++;
}
}
cout << anser << endl;
return ;
}
D
会爆long long 要用long double
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
const int mod = 1e9 + ;
const int gakki = + + + + 1e9;
const int N = 2e5 + ;
map<double, double> mp;
long double num[N];
long double now;
long double sheng;
int main()
{
ios_base::sync_with_stdio();
cin.tie();
long double sum = ;
long double anser = ;
int n;
cin >> n;
for (int i = ; i <= n; i++)
{
cin >> num[i];
sum += num[i];
mp[num[i]]++;
}
for (int i = ; i < n; i++)
{
sum -= num[i - ];
if (i != )
{
mp[num[i - ]]--;
}
sheng = n - i + - mp[num[i] - ] - mp[num[i] + ];
anser += sum - mp[num[i] - ] * (num[i] - ) - mp[num[i] + ] * (num[i] + ) - sheng * num[i];
}
cout << fixed << setprecision() << anser << endl;
return ;
}
JAVA版
import java.io.OutputStream;
import java.io.PrintWriter; import java.math.BigInteger;
import java.util.*;; public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream); SortedMap<Long, Long>ma = new TreeMap<>() ;
BigInteger result = new BigInteger("");
BigInteger currentSum = new BigInteger (""); int n = in.nextInt();
for (int i = ; i < n; i++) {
long x = in.nextInt(); long count = i - (ma.getOrDefault(x - ,0L) + ma.getOrDefault(x,0L) + ma.getOrDefault(x + ,0L));
long toRemove = (x - ) * ma.getOrDefault(x - ,0L) + (x)* ma.getOrDefault(x,0L) + (x + ) * ma.getOrDefault(x + ,0L);
BigInteger valueY = currentSum.subtract(new BigInteger(String.valueOf(toRemove))); result = result.add(new BigInteger(String.valueOf((x * count)))).subtract(valueY); currentSum = currentSum.add(new BigInteger(String.valueOf(x)));
ma.put(x, ma.getOrDefault(x,0L)+);
} out.println(result.toString()); in.close();
out.close();
}
}
E
题意:
给你K个长度为N的字符串 每个字符串可以交换任意两项一次 问你这N个字符串能不能最后都变为一个字符串
解:
以第一个字符串为主串 N枚举每个其他串 测出与其他串的汉明距离
然后K2枚举交换的位置 再N枚举其他串 看交换后是否满足
满足有两种情况 1.第一个字符串有两个相同字母 交换后的汉明距离为0 2.交换后的汉明距离为2
当当前交换的两项可以满足所有其他串时 交换这两项后的字符串就是目标串
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
const int mod = 1e9 + , gakki = + + + + 1e9;
const int MAXN = 1e5 + , MAXM = 1e5 + , N = 1e4 + ;
const int MAXQ = ;
int to[MAXM << ], nxt[MAXM << ], Head[MAXN], tot = ;
inline void addedge(int u, int v)
{
to[++tot] = v;
nxt[tot] = Head[u];
Head[u] = tot;
}
inline void read(int &v)
{
v = ;
char c = ;
int p = ;
while (c < '' || c > '')
{
if (c == '-')
{
p = -;
}
c = getchar();
}
while (c >= '' && c <= '')
{
v = (v << ) + (v << ) + c - '';
c = getchar();
}
v *= p;
}
string st[];
int num[][];
int hmdis[];
int n, k;
int flag = ;
int main()
{
ios_base::sync_with_stdio();
cin.tie();
cin >> k >> n;
for (int i = ; i <= k; i++)
{
cin >> st[i];
}
for (int i = ; i < n; i++)
{
num[][st[][i] - 'a']++;
if (num[][st[][i] - 'a'] > )
{
flag = ;
}
}
for (int i = ; i <= k; i++)
{
mem(num[], );
for (int j = ; j < n; j++)
{
num[][st[i][j] - 'a']++;
if (st[][j] != st[i][j])
{
hmdis[i]++;
}
}
for (int j = ; j <= ; j++)
{
if (num[][j] != num[][j])
{
cout << - << endl;
return ;
}
}
}
for (int i = ; i < n - ; i++)
{
for (int j = i + ; j < n; j++)
{
int now = ;
for (int w = ; w <= k; w++)
{
int cnt = hmdis[w];
if (st[][i] == st[w][i])
{
cnt++;
}
if (st[][j] == st[w][j])
{
cnt++;
}
if (st[][i] == st[w][j])
{
cnt--;
}
if (st[][j] == st[w][i])
{
cnt--;
}
if (cnt == || (cnt == && flag))
{
now++;
}
else
{
break;
}
}
if (now == k)
{
swap(st[][i], st[][j]);
cout << st[] << endl;
return ;
}
}
}
cout << - << endl;
return ;
}
Codeforces 903 绝对值1e19longdouble算贡献 汉明距离交换两项是否可行的更多相关文章
- Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song 算贡献+前缀和
E. Pretty Song time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CodeForces - 1228C(质因数分解+贡献法)
题意 https://vjudge.net/problem/CodeForces-1228C 首先先介绍一些涉及到的定义: 定义prime(x)表示x的质因子集合.举例来说,prime(140)={2 ...
- 如何交换两个等长整形数组使其数组和的差最小(C和java实现)
1. 问题描述: 有两个数组a,b,大小都为n,数组元素的值任意整形数,无序: 要求:通过交换a,b中的元素,使[数组a元素的和]与[数组b元素的和]之间的差最小. 2. 求解思路: 当前数组a和数组 ...
- 实现pow(int x, int y),即x的y次方 ; 异或交换两个数;
问题1:实现pow(int x, int y) ,即x的y次方 x的y次方就是有y个x连续乘机,代码如下: #include <stdio.h> #include <stdlib.h ...
- C++ 系列:交换两个数字
1. 创建中间变量 这是最快也是最简单的办法,例如: #include<stdio.h> int main(){ int a=10; int b=20; int temp; printf( ...
- c语言-交换两个整数
使用c来写一个函数来实现交换两个整数. 第一种 一般的方法,引用中间变量,方便快捷. void swap(int *a, int *b) { int tmp = *a; *a = *b; *b = t ...
- 用一条UPDATE语句交换两列的值
在SQL UPDATE语句中,"="右侧的值在整个UPDATE语句中都是一致的,所有更新同时发生!因此以下语句将在没有临时变量的情况下交换两列的值: UPDATE table SE ...
- JavaScript中交换两个变量的值得三种做法(代码实现)
javascript在编程时经常会涉及到如何交换两个变量的值,例如常见的冒泡排序,快速排序等:下面我讲根据自己近期所学总结几种常见的交换两个变量值的方法: 方法一:借助第三方变量交换两个变量的值 va ...
- c语言实现交换两个数的值
C语言中要实现交换两个数的值,可以有很多种方法,具体如下所述. 不使用中间变量: // 异或, a^=b^=a^=b; a ^= b; b ^= a; a ^= b; // 加减 a = a + b; ...
随机推荐
- jenkins与docker(DevOps二)
Jenkins官网 https://jenkins.io/download/ centos 7安装Docker https://www.cnblogs.com/stulzq/p/7743073.htm ...
- Python_元组、字典内建方法详解
目录 目录 前言 软件环境 元组Tuple count 查询一个元素在Tuple中的数量 index 查询元素在Tuple中的索引号 元组的遍历 字典Dictionary 创建一个字典对象 简单的创建 ...
- :成功配置 centos + nginx + .net core 2.0
https://segmentfault.com/a/1190000010763523
- activiti随笔记录
核心组件介绍 关键对象 1. Deployment:流程部署对象,部署一个流程时创建. 2. ProcessDefinitions:流程定义,部署成功后自动创建. 3. ...
- mysqli实现增删改查(转)
1.面向对象 在面向对象的方式中,mysqli被封装成一个类,它的构造方法如下: __construct ([ string $host [, string $username [, string $ ...
- MyBatis框架原理1:构建SqlSessionFactory的过程
SqlSessionFactoryBuilder 首先创建了一个SqlSessionFactoryBuilder对象,然后调用该对象的build方法加载全局XML配置的流文件构建出一个SqlSessi ...
- 简述Object(ActiveX)控件遮挡Dialog、select下拉框的解决办法
1.背景 最近在做项目的过程中,我们使用了Object控件,但是同时在上面写了一个select下拉框,因此每次点击下拉框的时候我们会发现,下拉框的部分内容被Object控件给遮挡了,调查研究后发现,我 ...
- react 中 EventEmitter 事件总线机制
此机制可用于 react 中兄弟组件中的通信 npm install events -S 事件总线: // eventBus.js import {EventEmitter} from 'events ...
- sql中生成随机字符串的function
create or replace function random_string(integer) returns text as $body$ ))::) , $)), ''); $body$ la ...
- 【洛谷p1781】宇宙总统
宇宙总统[题目链接] 关于题目算法,其实就是考排序,那我们直接sort不就好啦,显然不能. 这个题让我重新认识了cmp函数: 以下是我的心路历程: 看到这个题,嗯?这么简单的吗,我直接sort不就好啦 ...