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[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}};
const int mod = 1e9 + 7;
const int gakki = 5 + 2 + 1 + 19880611 + 1e9;
const int N = (1 << 22) + 5;
int main()
{
        int T;
        cin >> T;
        while (T--)
        {
                int flag=0;
                int n;
                cin >> n;
                for (int i = 0; i <= n / 3; i++)
                {
                        if ((n - 3 * i) % 7 == 0)
                        {
                                cout << "YES" << endl;
                                flag=1;
                                break;
                        }
                }
                if(!flag)
                {
                        cout<<"NO"<<endl;
                }
        }

        return 0;
}
View Code

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[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}};
const int mod = 1e9 + 7;
const int gakki = 5 + 2 + 1 + 19880611 + 1e9;
const int N = (1 << 22) + 5;
string ans[100005];
int cnt = 0;
int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        int h1, a1, c1;
        int h2, a2;
        cin >> h1 >> a1 >> c1;
        cin >> h2 >> a2;
        while (h2 > 0)
        {
                if (h2 - a1 <= 0)
                {
                        ans[++cnt] = "STRIKE";
                        h2 -= a1;
                        continue;
                }
                if (h1 - a2 <= 0)
                {
                        ans[++cnt] = "HEAL";
                        h1 += c1-a2;
                        continue;
                }
                ans[++cnt] = "STRIKE";
                h1 -= a2;
                h2 -= a1;
        }
        cout << cnt << endl;
        for (int i = 1; i <= cnt; i++)
        {
                cout << ans[i] << endl;
        }
        return 0;
}
View Code

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[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}};
const int mod = 1e9 + 7;
const int gakki = 5 + 2 + 1 + 19880611 + 1e9;
const int N = 5e3 + 5;
int vis[N];
int num[N];
int visit[N];
int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        int n;
        cin >> n;
        int maxn = -1;
        for (int i = 1; i <= n; i++)
        {
                cin >> num[i];
                maxn = max(maxn, num[i]);
        }
        sort(num + 1, num + 1 + n);
        for (int i = 1; i <= n; i++)
        {
                if (visit[i])
                {
                        continue;
                }
                int cur = num[i];
                int pre = i;
                vis[pre] = 1;
                visit[pre] = 1;
                for (int j = i + 1; j <= n; j++)
                {
                        if (num[j] > cur && !visit[j])
                        {
                                visit[j] = 1;
                                vis[pre] = 0;
                                cur = num[j];
                                pre = j;
                                vis[pre] = 1;
                        }
                }
        }
        int anser = 0;
        for (int i = 1; i <= n; i++)
        {
                if (vis[i])
                {
                        anser++;
                }
        }
        cout << anser << endl;
        return 0;
}
View Code

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[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}};
const int mod = 1e9 + 7;
const int gakki = 5 + 2 + 1 + 19880611 + 1e9;
const int N = 2e5 + 5;
map<double, double> mp;
long double num[N];
long double now;
long double sheng;
int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        long double sum = 0;
        long double anser = 0;
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
                cin >> num[i];
                sum += num[i];
                mp[num[i]]++;
        }
        for (int i = 1; i < n; i++)
        {
                sum -= num[i - 1];
                if (i != 1)
                {
                        mp[num[i - 1]]--;
                }
                sheng = n - i + 1 - mp[num[i] - 1] - mp[num[i] + 1];
                anser += sum - mp[num[i] - 1] * (num[i] - 1) - mp[num[i] + 1] * (num[i] + 1) - sheng * num[i];
        }
        cout << fixed << setprecision(0) << anser << endl;
        return 0;
}
View Code

 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("0");
        BigInteger currentSum  = new BigInteger ("0");


        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            long x = in.nextInt();

            long count = i - (ma.getOrDefault(x - 1,0L) + ma.getOrDefault(x,0L) + ma.getOrDefault(x + 1,0L));
            long toRemove = (x - 1) * ma.getOrDefault(x - 1,0L) + (x)* ma.getOrDefault(x,0L) + (x + 1) * ma.getOrDefault(x + 1,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)+1);
        }

        out.println(result.toString());

        in.close();
        out.close();
    }
}
View Code

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[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}};
const int mod = 1e9 + 7, gakki = 5 + 2 + 1 + 19880611 + 1e9;
const int MAXN = 1e5 + 5, MAXM = 1e5 + 5, N = 1e4 + 5;
const int MAXQ = 100010;
int to[MAXM << 1], nxt[MAXM << 1], Head[MAXN], tot = 1;
inline void addedge(int u, int v)
{
        to[++tot] = v;
        nxt[tot] = Head[u];
        Head[u] = tot;
}
inline void read(int &v)
{
        v = 0;
        char c = 0;
        int p = 1;
        while (c < '0' || c > '9')
        {
                if (c == '-')
                {
                        p = -1;
                }
                c = getchar();
        }
        while (c >= '0' && c <= '9')
        {
                v = (v << 3) + (v << 1) + c - '0';
                c = getchar();
        }
        v *= p;
}
string st[3005];
int num[2][30];
int hmdis[3000];
int n, k;
int flag = 0;
int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cin >> k >> n;
        for (int i = 1; i <= k; i++)
        {
                cin >> st[i];
        }
        for (int i = 0; i < n; i++)
        {
                num[0][st[1][i] - 'a']++;
                if (num[0][st[1][i] - 'a'] > 1)
                {
                        flag = 1;
                }
        }
        for (int i = 2; i <= k; i++)
        {
                mem(num[1], 0);
                for (int j = 0; j < n; j++)
                {
                        num[1][st[i][j] - 'a']++;
                        if (st[1][j] != st[i][j])
                        {
                                hmdis[i]++;
                        }
                }
                for (int j = 0; j <= 25; j++)
                {
                        if (num[1][j] != num[0][j])
                        {
                                cout << -1 << endl;
                                return 0;
                        }
                }
        }
        for (int i = 0; i < n - 1; i++)
        {
                for (int j = i + 1; j < n; j++)
                {
                        int now = 0;
                        for (int w = 1; w <= k; w++)
                        {
                                int cnt = hmdis[w];
                                if (st[1][i] == st[w][i])
                                {
                                        cnt++;
                                }
                                if (st[1][j] == st[w][j])
                                {
                                        cnt++;
                                }
                                if (st[1][i] == st[w][j])
                                {
                                        cnt--;
                                }
                                if (st[1][j] == st[w][i])
                                {
                                        cnt--;
                                }
                                if (cnt == 2 || (cnt == 0 && flag))
                                {
                                        now++;
                                }
                                else
                                {
                                        break;
                                }
                        }
                        if (now == k)
                        {
                                swap(st[1][i], st[1][j]);
                                cout << st[1] << endl;
                                return 0;
                        }
                }
        }
        cout << -1 << endl;
        return 0;
}
View Code

 

转载于:https://www.cnblogs.com/Aragaki/p/9118823.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值