本文主要是介绍Codeforces Round #247 (Div. 2) A B,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
A
就是下标求和,无难度
#include <stdio.h>
#include <stdlib.h>
#include <math.h>char s[1000000];
int a[4];int main()
{scanf ("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]);scanf ("%s",s);char *p = s;int ans = 0;while (*p != '\0'){ans += a[*p - '0' - 1];p++;}printf ("%d\n",ans);return 0;
}
B
暴力出来的
#include <stdio.h>
#include <stdlib.h>
#include <math.h>int g[6][6];int pd (int i,int k,int j,int h,int l)
{int ans = 0;ans += g[i][k] + g[k][i] + g[j][h] + g[h][j];ans += g[j][k] + g[k][j] + g[l][h] + g[h][l];ans += g[j][h] + g[h][j];ans += g[l][h] + g[h][l];return ans;
}int main()
{int i,k,j,h,l;int ans,imax = 0;for (i = 0;i < 5;i++)for (k = 0;k < 5;k++)scanf ("%d",&g[i][k]);for (i = 0;i < 5;i++){for (k = 0;k < 5;k++){if (k == i)continue;for (j = 0;j < 5;j++){if (j == i || j == k)continue;for (h = 0;h < 5;h++){if (h == i || h == k || h ==j)continue;for (l = 0;l < 5;l++){if (l == i || l == k || l == j || l ==h)continue;ans = pd (i,k,j,h,l);imax = imax > ans ? imax : ans;}}}}}printf ("%d\n",imax);return 0;
}
这篇关于Codeforces Round #247 (Div. 2) A B的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!