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; ...
随机推荐
- 清除表单input输入框内数据
清除表单input输入框内数据 1. $(':input','#addVoucherType') //'#addVoucherType'表单id .not(':button') .val('') .r ...
- unittest 和 pytest 对比
一.用例编写规则 1.unittest提供了test cases.test suites.test fixtures.test runner相关的类,让测试更加明确.方便.可控.使用unittest编 ...
- 【miscellaneous】北斗短报文
北斗系统最大的特色在于有源定位和短报文特色服务,不止解决了中国有无卫星导航系统的问题,还能将短信和导航结合,是中国北斗卫星导航系统的独特发明,也是一大优势. 北斗的短报文功能,在国防.民生和应急救援等 ...
- 配置tomcat-users.xml文件
今天在学习登录日志保存时出现一系列错误,想查看浏览器后台的session,结果忘记怎么看用户名和密码了,下面是转载自民工也Coding的一篇文章, 文章链接为:http://www.cnblogs.c ...
- excel常用快捷键和技巧
1. Ctrl+方向键,对单元格光标快速移动,移动到数据边缘(空格位置). 2. Ctrl+方向键,对单元格光标快速移动,移动到数据边缘(空格位置). 3. Ctrl+A,选择整张表. 4. Ctrl ...
- 交换机安全学习笔记 第五章 DHCP缺陷攻击
关于DHCP攻击有如下几类攻击方式: 一.耗尽DHCP地址池 通过随机生成源MAC地址,然后伪造DHCPDISCOVER数据包.耗尽DHCP服务器地址池. 免费的攻击工具: Yersi ...
- 【转】mysql索引的探究
转自:https://mp.weixin.qq.com/s/XTu7jERv3A0CIAzlECFnlA 相信很多人对于MySQL的索引都不陌生,索引(Index)是帮助MySQL高效获取数据的数据结 ...
- Mycat+Mysql主从复制实现双机热备
Mycat+Mysql主从复制实现双机热备 一.mysql主从配置原理 双机热备的概念简单说一下,就是要保持两个数据库的状态自动同步.对任何一个数据库的操作都自动应用到另外一个数据库,始终保持两个数据 ...
- BZOJ 1257 余数之和 题解
题面 这道题是一道整除分块的模板题: 首先,知道分块的人应该知道,n/i最多有2*sqrt(n)种数,但这和余数有什么关系呢? 注意,只要n/i的值和n/(i+d)的值一样,那么n%i到n%(i+d) ...
- c++ try_throw_catch异常处理
参考https://www.cnblogs.com/xiaojianliu/articles/8900795.html 在程序设计时,针对不同的异常情况,预先设定异常信息,在程序运行时,根据异常提示信 ...