1 solutions
-
0
70pts
#include<bits/stdc++.h> using namespace std; const int N=1e5+10; pair<int,int> b[]={{0,6},{1,2},{2,5},{4,4},{6,6},{7,3},{8,7}}; int cnt,x; int ans[N],idx; bool dfs(int u,int sum) { if(!u) //走到第一位了 { if(sum==x) //刚好用完 { for(int i=0;i<idx;i++) { cout<<ans[i]; } cout<<endl; return true; } else return false; } if(sum+u*7<x) return false; //如果剩余的全部选8都不够 for(int i=0;i<7;i++) { if(u==cnt&&i==0) continue;//如果是第一位数字不能选0 ans[idx++]=b[i].first; if(dfs(u-1,sum+b[i].second)) return true; else idx--; } } int main() { int T; cin>>T; while(T--) { idx=0; cin>>x; cnt=(x+6)/7;//计算最多位数 if(!dfs(cnt,0)) cout<<-1<<endl; } return 0; }100pts
#include <iostream> #include <algorithm> using namespace std; int a[7] = {8, -1, 1, 7, 4, 2, 6}; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int x = n % 7; if (n <= 7) { cout << a[x] << endl; continue; } string ans = ""; if (x == 0) { for (int i = 0; i < n / 7; i++) ans += "8"; } else if (x == 1) { ans += "10"; for (int i = 0; i < n / 7 - 1; i++) ans += "8"; } else if (x == 2) { ans += "18"; for (int i = 0; i < n / 7 - 1; i++) ans += "8"; } else if (x == 3) { if (n / 7 == 1) ans = "22"; else { ans += "200"; for (int i = 0; i < n / 7 - 2; i++) ans += "8"; } } else if (x == 4) { ans += "20"; for (int i = 0; i < n / 7 - 1; i++) ans += "8"; } else if (x == 5) { ans += "28"; for (int i = 0; i < n / 7 - 1; i++) ans += "8"; } else if (x == 6) { ans += "68"; for (int i = 0; i < n / 7 - 1; i++) ans += "8"; } cout << ans << endl; } }
- 1
Information
- ID
- 2602
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By