。。。。。。

今天不管做什么题,都莫名SB。hihocoder还有几道待补坑的题目。。。

A题链接:A


AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int a[3][2];
bool judge(int x, int y, int z)
{
    if(a[x][0] == a[y][0])
    {
        if(a[x][1] + a[y][1] == a[z][0] && a[x][1] + a[y][1] == a[z][1] + a[x][0])
            return true;
        if(a[x][1] + a[y][1] == a[z][1] && a[x][1] + a[y][1] == a[z][0] + a[x][0])
            return true;
    }
    if(a[x][0] == a[y][1])
    {
        if(a[x][1] + a[y][0] == a[z][0] && a[x][1] + a[y][0] == a[z][1] + a[x][0])
            return true;
        if(a[x][1] + a[y][0] == a[z][1] && a[x][1] + a[y][0] == a[z][0] + a[x][0])
            return true;
    }
    if(a[x][1] == a[y][0])
    {
        if(a[x][0] + a[y][1] == a[z][0] && a[x][0] + a[y][1] == a[z][1] + a[x][1])
            return true;
        if(a[x][0] + a[y][1] == a[z][1] && a[x][0] + a[y][1] == a[z][0] + a[x][1])
            return true;
    }
    if(a[x][1] == a[y][1])
    {
        if(a[x][0] + a[y][0] == a[z][0] && a[x][0] + a[y][0] == a[z][1] + a[x][1])
            return true;
        if(a[x][0] + a[y][0] == a[z][1] && a[x][0] + a[y][0] == a[z][0] + a[x][1])
            return true;
    }
    return false;
}
void solve(int x){
    if(a[x][0] > a[x][1])
        swap(a[x][0], a[x][1]);
}
bool same(int x, int y){
    return (a[x][0] == a[y][0] && a[x][1] == a[y][1]);
}
int main()
{
    while(scanf("%d%d%d%d%d%d", &a[0][0], &a[0][1], &a[1][0], &a[1][1], &a[2][0], &a[2][1]) != EOF)
    {
        bool flag = false;
        solve(0); solve(1); solve(2);
        if(a[0][1] == a[1][1] && a[0][1] == a[2][1])
        {
            if(a[0][0] + a[1][0] + a[2][0] == a[0][1])
                flag = true;
        }
        if(flag)
        {
            printf("YES\n");
            continue;
        }
        flag = (judge(0, 1, 2) || judge(0, 2, 1) || judge(1, 2, 0));
        printf(flag ? "YES\n" : "NO\n");
    }
    return 0;
}

B题链接:B


AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
map<string, int> fp;
int main()
{
    int n;
    while(cin >> n)
    {
        fp.clear();
        for(int i = 0; i < n; i++)
        {
            string str; cin >> str;
            if(!fp[str]) cout << "OK";
            else { cout << str << fp[str];}
            cout << endl; fp[str]++;
        }
    }
    return 0;
}


C题链接:C

AC代码:感觉题意不对。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
    int n, m;
    while(cin >> n >> m){
        cout << 1LL * n * (n+1) % m * (2*n+1) % m << endl;
    }
    return 0;
}


D题链接:D

思路:dp[i][k]表示前i件物品选k*2件的最小代价。

AC代码:


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
typedef long long LL;
const int MAXN = 2005;
const int INF = 0x3f3f3f3f;
int dp[MAXN][MAXN], a[MAXN];
int main()
{
    int t; cin >> t;
    while(t--)
    {
        int n, k; cin >> n >> k;
        for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
        if(n == 2) { cout << abs(a[2]-a[1]) * abs(a[2]-a[1]) << endl; continue; }
        memset(dp, INF, sizeof(dp)); dp[0][0] = 0; sort(a+1, a+n+1);
        for(int i = 1; i <= n; i++)
        {
            for(int j = 0; j <= k; j++)
            {
                if(j * 2 > i) break;
                if(j == 0) dp[i][j] = 0;
                else dp[i][j] = min(dp[i-1][j], dp[i-2][j-1] + (a[i]-a[i-1]) * (a[i]-a[i-1]));
            }
        }
        cout << dp[n][k] << endl;
    }
    return 0;
}


E题链接:E

思路:x = log10 (a^b) -> 10^x = a^b。

取x的小数部分,结果就是10^(x的小数部分+c-1),判下不含c位的情况。思路应该没错,莫名WA到死。待补坑。

如 log10(x.y * 10^z) (我们log10一下)-> z + log10(x.y)。求出x.y*10^(c-1)就可以了。

为什么WA 啊。。。。。。

WA代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 1000001;
char str[MAXN];
int main()
{
    int a, b, c;
    while(scanf("%d%d%d", &a, &b, &c) != EOF)
    {
        double ans = 1.0 * b * log10(a*1.0);
        LL bit = (LL)ans; ans = ans - bit;
        if(bit < c) c = bit+1;
        double res = pow(10, ans)*pow(10, c*1.000000-1);
        sprintf(str, "%lf", res);
        int num = 0;
        for(int i = 0; i < MAXN; i++)
        {
            if(str[i] == '.') break;
            num = num * 10 + (str[i] - '0');
        }
        printf("%d\n", num);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值