Codeforces Round #279 (Div. 2)
来源:互联网 发布:淘宝天猫优惠群可靠吗 编辑:程序博客网 时间:2024/06/07 06:40
记录一下,然后输出来就可以了。
/***********************************************\ |Author: YMC |Created Time: 2014/11/23 17:12:30 |File Name: a.cpp |Description: \***********************************************/#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>#include <algorithm>#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <stack>#define L(rt) (rt<<1)#define R(rt) (rt<<1|1)#define mset(l,n) memset(l,n,sizeof(l))#define rep(i,n) for(int i=0;i<n;++i)#define maxx(a) memset(a, 0x3f, sizeof(a))#define zero(a) memset(a, 0, sizeof(a))#define srep(i,n) for(int i = 1;i <= n;i ++)#define MP make_pairconst int inf=0x3f3f3f3f ;const double eps=1e-8 ;const double pi=acos (-1.0);typedef long long ll;using namespace std;int a[5005];int b[5005];int c[5005];int t1,t2,t3;int n;int main() {//freopen("input.txt","r",stdin); while(~scanf("%d",&n)) { int tp; t1 = t2 = t3 = 0; rep(i,n) { scanf("%d",&tp); if(tp == 1) { a[t1 ++] = i+1; } else if(tp == 2) { b[t2++] = i+1; } else { c[t3 ++] = i+1; } } tp = min(t1,t2); tp = min(tp,t3); printf("%d\n",tp); for(int i=0;i<tp;++i) { printf("%d %d %d\n",a[i],b[i],c[i]); } }return 0;}
隔一个来搞。先从为0的开始,可以把奇数位置的弄出来了。然后奇数位置的就是处理出来哪个是第一个,然后再和前面一样搞。
/***********************************************\ |Author: YMC |Created Time: 2014/11/23 17:20:40 |File Name: b.cpp |Description: \***********************************************/#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>#include <algorithm>#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <stack>#define L(rt) (rt<<1)#define R(rt) (rt<<1|1)#define mset(l,n) memset(l,n,sizeof(l))#define rep(i,n) for(int i=0;i<n;++i)#define maxx(a) memset(a, 0x3f, sizeof(a))#define zero(a) memset(a, 0, sizeof(a))#define srep(i,n) for(int i = 1;i <= n;i ++)#define MP make_pairconst int inf=0x3f3f3f3f ;const double eps=1e-8 ;const double pi=acos (-1.0);typedef long long ll;using namespace std;int n;int m1[1000002];int m2[1000002];int m3[1000002];bool mm[1000002];int num[1000002];int a,b;int tt;int main() {//freopen("input.txt","r",stdin); scanf("%d",&n); memset(mm,false,sizeof(mm)); tt = 0; rep(i,n) { scanf("%d %d",&a,&b); m1[a] = b; m2[b] = a; mm[b] = true; num[tt ++] = a; } int ff; rep(i,tt) { if(num[i] != 0 && !mm[num[i]]) { ff = num[i]; break; } } int tot = 2; int p = 0; while(tot <= n) { m3[tot] = m1[p]; p = m1[p]; tot += 2; } //srep(i,n) printf("%d ",m3[i]); tot = 3; m3[1] = ff; p = ff; //cout<<m2[0]<<endl; while(tot <= n) { m3[tot] = m1[p]; p = m1[p]; tot += 2; } srep(i,n) printf("%d ",m3[i]); puts("");return 0;}
先正着扫一遍,标记哪些前缀可以被a除尽。然后再扫后缀。扫后缀可以加一个快速幂的优化。
/***********************************************\ |Author: YMC |Created Time: 2014/11/23 17:47:41 |File Name: c.cpp |Description: \***********************************************/#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>#include <algorithm>#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <stack>#define L(rt) (rt<<1)#define R(rt) (rt<<1|1)#define mset(l,n) memset(l,n,sizeof(l))#define rep(i,n) for(int i=0;i<n;++i)#define maxx(a) memset(a, 0x3f, sizeof(a))#define zero(a) memset(a, 0, sizeof(a))#define srep(i,n) for(int i = 1;i <= n;i ++)#define MP make_pairconst int inf=0x3f3f3f3f ;const double eps=1e-8 ;const double pi=acos (-1.0);typedef long long ll;using namespace std;char s[1000006];bool m1[1000006];ll m2[1000006];int pp[1000006];ll a,b;ll ppow(ll x,ll n,ll mod){ ll res = 1; while(n > 0){ if(n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res;}int main() { //freopen("input.txt","r",stdin); scanf("%s",&s); scanf("%I64d %I64d",&a,&b); int len = strlen(s); ll now = 0; int tot = 0; rep(i,len) { now = now * 10 + s[i] - '0'; if(now % a == 0 && s[i+1] != '0') { m1[i] = true; //cout<<i<<endl; pp[tot ++] = i; } now = now % a; } if(pp[tot - 1] == len - 1) tot --; int ans = -1; for(int i = tot - 1;i >= 0;--i) { int p = pp[i]; now = 0; for(int j = p+1;j < len;++j) { if(m2[j] == 0){ now = now * 10 + s[j] - '0'; now = now % b; } else { now = now*ppow(10,len-j,b) + m2[j]; now = now % b; break; } } if(now == 0) { ans = p; break; } else { m2[p+1] = now; //cout<<"now == "<<now<<endl; } } if(ans == -1) { puts("NO"); } else { puts("YES"); for(int i=0;i<=ans;++i) { putchar(s[i]); } puts(""); for(int i=ans+1;i<len;++i) { putchar(s[i]); } puts(""); }return 0;}
记忆化搜索,保存路径。具体可以看代码
/***********************************************\ |Author: YMC |Created Time: 2014/11/23 18:08:30 |File Name: d.cpp |Description: \***********************************************/#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>#include <algorithm>#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <stack>#define L(rt) (rt<<1)#define R(rt) (rt<<1|1)#define mset(l,n) memset(l,n,sizeof(l))#define rep(i,n) for(int i=0;i<n;++i)#define maxx(a) memset(a, 0x3f, sizeof(a))#define zero(a) memset(a, 0, sizeof(a))#define srep(i,n) for(int i = 1;i <= n;i ++)#define MP make_pairconst int inf=0x3f3f3f3f ;const double eps=1e-8 ;const double pi=acos (-1.0);typedef long long ll;using namespace std;ll a1,b1,a2,b2;ll aa1,bb1,aa2,bb2;int dp[50][50][50][50];int dd[50][50][50][50];int solve(ll a1,ll b1,ll a2,ll b2,int a,int b,int c,int d) { if(dp[a][b][c][d] != -1) { return dp[a][b][c][d]; } ll tt1,tt2; tt1 = a1 * b1; tt2 = a2 * b2; if(tt1 == tt2) { dp[a][b][c][d] = 0; dd[a][b][c][d] = 0; return 0; } //dp[0][0][0][0] = inf; int &ans = dp[a][b][c][d]; ans = inf; int tp; if(tt1 > tt2) { if(a1 % 2 == 0) { tp = ans; ans = min(solve(a1/2,b1,a2,b2,a+1,b,c,d) + 1,ans); if(ans != tp) { dd[a][b][c][d] = 1; } } if(b1 % 2 == 0) { tp = ans; ans = min(solve(a1,b1/2,a2,b2,a+1,b,c,d) + 1,ans); if(ans != tp) { dd[a][b][c][d] = 2; } } if(a1 % 3 == 0) { tp = ans; ans = min(solve(a1/3*2,b1,a2,b2,a,b+1,c,d) + 1,ans); if(ans != tp) { dd[a][b][c][d] = 3; } } if(b1 % 3 == 0) { tp = ans; ans = min(solve(a1,b1/3*2,a2,b2,a,b+1,c,d) + 1,ans); if(ans != tp) { dd[a][b][c][d] = 4; } } } else { if(a2 % 2 == 0) { tp = ans; ans = min(solve(a1,b1,a2/2,b2,a,b,c+1,d) + 1,ans); if(ans != tp) { dd[a][b][c][d] = 5; } } if(b2 % 2 == 0) { tp = ans; ans = min(solve(a1,b1,a2,b2/2,a,b,c+1,d) + 1,ans); if(ans != tp) { dd[a][b][c][d] = 6; } } if(a2 % 3 == 0) { tp = ans; ans = min(solve(a1,b1,a2/3*2,b2,a,b,c,d+1) + 1,ans); if(ans != tp) { dd[a][b][c][d] = 7; } } if(b2 % 3 == 0) { tp = ans; ans = min(solve(a1,b1,a2,b2/3*2,a,b,c,d+1) + 1,ans); if(ans != tp) { dd[a][b][c][d] = 8; } } } return ans;}void get(int a,int b,int c,int d) { int tt = dd[a][b][c][d]; if(tt == 0) return ; if(tt == 1) { a1 /= 2; get(a + 1,b,c,d); } if(tt == 2) { b1 /= 2; get(a + 1,b,c,d); } if(tt == 3) { a1 /= 3; a1 *= 2; get(a,b+1,c,d); } if(tt == 4) { b1 /= 3; b1 *= 2; get(a,b+1,c,d); } if(tt == 5) { a2 /= 2; get(a,b,c+1,d); } if(tt == 6) { b2 /= 2; get(a,b,c+1,d); } if(tt == 7) { a2 /= 3; a2 *= 2; get(a,b,c,d+1); } if(tt == 8) { b2 /= 3; b2 *= 2; get(a,b,c,d+1); } }int main() {//freopen("input.txt","r",stdin); scanf("%I64d %I64d",&a1,&b1); scanf("%I64d %I64d",&a2,&b2); memset(dp,-1,sizeof(dp)); int ans = solve(a1,b1,a2,b2,0,0,0,0); if(ans >= inf) ans = -1; //solve(a1,b1,a2,b2,0,0,0,0); if(ans == -1) { puts("-1"); } else { printf("%d\n",ans); get(0,0,0,0); printf("%I64d %I64d\n",a1,b1); printf("%I64d %I64d\n",a2,b2); }return 0;}
e题好像也可以随便搞。自己的写搓了。。。
0 0
- Codeforces Round #279 (Div. 2)
- Codeforces Round #279 (Div. 2)
- Codeforces Round #279 (Div. 2)
- Codeforces Round #279 (Div. 2)
- Codeforces Round #279 (Div. 2)
- Codeforces Round #279 (Div. 2)
- Codeforces Round #279 (Div. 2)
- 【codeforces】Codeforces Round #279 (Div. 2) 题解
- Codeforces Round #279 (Div. 2) D. Chocolate
- Codeforces Round #279 (Div. 2) E
- Codeforces Round #279 (Div. 2) C
- Codeforces Round #279 (Div. 2) F
- Codeforces Round #279 (Div. 2) D
- Codeforces Round #279 (Div. 2)B. Queue
- Codeforces Round #279 (Div. 2) E
- Codeforces Round #279 (Div. 2) B. Queue
- Codeforces Round #279 (Div. 2) D. Chocolate
- Codeforces Round #279 (Div. 2) F
- HDU 3341 Lost's revenge AC自动机 + 变进制状压DP
- Java Collection
- 第十三周项目1.1创建一个20的数的数组,初始化前10个,输入后十个,从前往后输出所有元素
- Java Notes-2
- 记录22--invalid option `abi=aapcs-linux'错误提示
- Codeforces Round #279 (Div. 2)
- 计算机视觉会议和期刊分类
- bzoj 1043: [HAOI2008]下落的圆盘
- 第3章 字符串
- poj2632
- hadoop2.4.1的伪分布环境搭建
- openwt 将软件安装到u盘
- Android 获取屏幕分辨率
- 第十三周项目1.2创建一个长度为10的数组,由后往前输出,然后加倍并输出