Little C Loves 3 I(CodeForces 1047A)
阿新 • • 發佈:2018-12-13
Description
Little C loves number «3» very much. He loves all things about it.
Now he has a positive integer nn. He wants to split nn into 33 positive integers a,b,ca,b,c, such that a+b+c=na+b+c=n and none of the 33 integers is a multiple of 33. Help him to find a solution.
Input
A single line containing one integer nn (3≤n≤1093≤n≤109) — the integer Little C has.
Output
Print 33 positive integers a,b,ca,b,c in a single line, such that a+b+c=na+b+c=n and none of them is a multiple of 33.
It can be proved that there is at least one solution. If there are multiple solutions, print any of them.
Sample Input
Input
3
Output
1 1 1
Input
233
Output
77 77 79
程式碼如下:
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<stack> #include<vector> #include<queue> #include<set> #include<algorithm> #define max(a,b) (a>b?a:b) #define min(a,b) (a<b?a:b) #define swap(a,b) (a=a+b,b=a-b,a=a-b) #define maxn 320007 #define N 100000000 #define INF 0x3f3f3f3f #define mod 1000000009 #define e 2.718281828459045 #define eps 1.0e18 #define PI acos(-1) #define lowbit(x) (x&(-x)) #define read(x) scanf("%d",&x) #define put(x) printf("%d\n",x) #define memset(x,y) memset(x,y,sizeof(x)) #define Debug(x) cout<<x<<" "<<endl #define lson i << 1,l,m #define rson i << 1 | 1,m + 1,r #define ll long long //std::ios::sync_with_stdio(false); //cin.tie(NULL); using namespace std; int main() { int n; cin>>n; if((n-2)%3==0) cout<<"1 2 "<<n-3<<endl; else cout<<"1 1 "<<n-2<<endl; return 0; }
做的時候短路了,用了一個特別麻煩的方法,以此借鑑:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) (a=a+b,b=a-b,a=a-b)
#define maxn 320007
#define N 100000000
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e 2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
//std::ios::sync_with_stdio(false);
//cin.tie(NULL);
using namespace std;
int main()
{
int n;
cin>>n;
if(n==5)
cout<<"1 2 2"<<endl;
else if(n%3==0)
{
int m=n/3;
if(m%3!=0)
cout<<m<<" "<<m<<" "<<m<<endl;
else
cout<<m-1<<" "<<m-1<<" "<<m+2<<endl;
}
else
{
int m=n/3;
int k=n%3;
int a[3]={m,m,m+k};
if(a[0]%3!=0&&a[1]%3!=0&&a[2]%3!=0)
cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
else
{
if(m%3==0)
{
a[0]--;
a[1]--;
a[2]+=2;
if(a[0]%3!=0&&a[1]%3!=0&&a[2]%3!=0)
cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
else
cout<<a[0]-1<<" "<<a[1]<<" "<<a[2]+1<<endl;
}
else
{
a[0]--;
a[1]--;
a[2]+=2;
if(a[0]%3!=0)
cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
else
cout<<a[0]-1<<" "<<a[1]+1<<" "<<a[2]<<endl;
}
}
}
return 0;
}