栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3397 Change the Major

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3397 Change the Major

#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>#include<algorithm>#include<map>#include<set>#include<queue>#include<vector>using namespace std;typedef long long lld;#define pb push_back#define mp make_pair#define X first#define Y secondchar str[110];int get() {scanf("%s", str);if (str[0] == 'M')return 2;if (str[1] == 'o')return 0;return 1;}struct Node {int at, to;double s;void in() {at = get();to = get();scanf("%lf", &s);}} p[110];bool cmp(Node a, Node b) {return a.s < b.s;}lld dp1[110];lld dp2[110];int n;lld tof(int i, int x, int y);lld change(int begin, int to) {bool same=true;for(int i=begin+1;i<n;i++)if(p[i].at != p[begin].at)same=false;if(same){int num=n-begin;int x=p[begin].at;int y=to;int L=max(x-y,y-x);for(int i=begin;i<n;i++)p[i].at=to;if(L == 2)return dp2[num];else if(L == 1)return dp1[num];elsereturn 0;}else{lld cnt = 0;for (int i = begin; i < n; i++){cnt += tof(i, p[i].at, to);}return cnt;}}lld tof(int i, int x, int y) {lld ans = 0;if (x == y)return 0;if (x == 0 && y == 1) {ans += change(i + 1, 2);ans++;} else if (x == 0 && y == 2) {ans += change(i + 1, 2);ans += change(i + 1, 0);ans += 2;} else if (x == 1 && y == 0) {ans += change(i + 1, 2);ans++;} else if (x == 1 && y == 2) {ans += change(i + 1, 0);ans++;} else if (x == 2 && y == 0) {ans += change(i + 1, 0);ans += change(i + 1, 2);ans += 2;} else if (x == 2 && y == 1) {ans += change(i + 1, 0);ans++;}p[i].at = y;return ans;}int main() {dp1[0]=dp2[0]=0;for(int i=1;i<=20;i++){dp1[i]=dp1[i-1]+dp2[i-1]+1;dp2[i]=dp2[i-1]*3+2;}while (scanf("%d", &n) != EOF) {for (int i = 0; i < n; i++)p[i].in();sort(p, p + n, cmp);lld ans = 0;for (int i = 0; i < n; i++) {int x = p[i].at;int y = p[i].to;ans += tof(i, x, y);}cout << ans << endl;}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371943.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号