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算贡献 汉明距离交换两项是否可行的更多相关文章

  1. 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 ...

  2. CodeForces - 1228C(质因数分解+贡献法)

    题意 https://vjudge.net/problem/CodeForces-1228C 首先先介绍一些涉及到的定义: 定义prime(x)表示x的质因子集合.举例来说,prime(140)={2 ...

  3. 如何交换两个等长整形数组使其数组和的差最小(C和java实现)

    1. 问题描述: 有两个数组a,b,大小都为n,数组元素的值任意整形数,无序: 要求:通过交换a,b中的元素,使[数组a元素的和]与[数组b元素的和]之间的差最小. 2. 求解思路: 当前数组a和数组 ...

  4. 实现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 ...

  5. C++ 系列:交换两个数字

    1. 创建中间变量 这是最快也是最简单的办法,例如: #include<stdio.h> int main(){ int a=10; int b=20; int temp; printf( ...

  6. c语言-交换两个整数

    使用c来写一个函数来实现交换两个整数. 第一种 一般的方法,引用中间变量,方便快捷. void swap(int *a, int *b) { int tmp = *a; *a = *b; *b = t ...

  7. 用一条UPDATE语句交换两列的值

    在SQL UPDATE语句中,"="右侧的值在整个UPDATE语句中都是一致的,所有更新同时发生!因此以下语句将在没有临时变量的情况下交换两列的值: UPDATE table SE ...

  8. JavaScript中交换两个变量的值得三种做法(代码实现)

    javascript在编程时经常会涉及到如何交换两个变量的值,例如常见的冒泡排序,快速排序等:下面我讲根据自己近期所学总结几种常见的交换两个变量值的方法: 方法一:借助第三方变量交换两个变量的值 va ...

  9. c语言实现交换两个数的值

    C语言中要实现交换两个数的值,可以有很多种方法,具体如下所述. 不使用中间变量: // 异或, a^=b^=a^=b; a ^= b; b ^= a; a ^= b; // 加减 a = a + b; ...

随机推荐

  1. fixture详细介绍-作为参数传入,error和failed区别

    前言 fixture是pytest的核心功能,也是亮点功能,熟练掌握fixture的使用方法,pytest用起来才会得心应手! fixture简介 fixture的目的是提供一个固定基线,在该基线上测 ...

  2. PHP 异步执行方式

    在工作中我们经常遇到一些比较耗时的任务,比如用户注册发送邮件,审核短信通知等功能,同步执行这些功能的话,响应时间就会变长,所以一般我们会用队列去管理这些功能,但是如果条件不允许怎么办,今天get了一个 ...

  3. 关于token的理解

    什么是token token的意思是“令牌”,是服务端生成的一串字符串,作为客户端进行请求的一个标识. 当用户第一次登录后,服务器生成一个token并将此token返回给客户端,以后客户端只需带上这个 ...

  4. C#学习笔记二 (资源托管,泛型,数组和元组,运算符和类型强制转换)

     托管和非托管资源 1.托管资源是指GC管理的内存空间,非托管资源是指文件句柄,网络连接,数据库连接等. 2.方法中临时申请的变量,被存放在栈中.栈存储非对象成员的值数据.例如在方法中有B b=new ...

  5. GCC+Make 自动生成 Makefile 依赖

    目录 BASIS wildcard .PHONY 静态模式 常用自动变量 自动生成依赖(GCC) -M 参数 编写 Makefile Makefile 细节说明 其他 本文内容基于 GNU MAKE. ...

  6. 【Angular5】 返回前一页面 go back to previous page

    import { Component, OnInit } from '@angular/core'; import { Router} from '@angular/router'; import { ...

  7. Junit4 简单使用

    一.环境搭建 对于习惯使用Eclipse开发平台来说,Junit早已是非常通常的插件,在Eclipse开发平台中,可以非常方便地搭建Junit测试环境. 1.在Eclipse上创建工程,任何Java工 ...

  8. IntelliJ IDEA将导入的项目转成maven项目

    今天导入公司的maven项目,发现结构不对劲,难怪说为啥一直不能部署tomcat,后面百度才了解到导入这个项目还不是maven项目,首先需要把这个项目变成maven项目,然后再进行tomcat的部署下 ...

  9. UML(统一建模语言)包含9种图

    UML分为静态图.动态图 动态图:虚壮活血 () 静态图:租用配对累()

  10. python 爬取百度url

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2017-08-29 18:38:23 # @Author : EnderZhou (z ...