标签:ch EOF int void Codeforces hasRead 1244C include
题意描述
\(x+y+z=n\)
\(xw+yd=p\)
求是否有满足方程的\((x,y,z)\),没有输出\(-1\)
思路1(枚举)
由于\(d<w\),平局的分数是严格小于获胜的分数。当\(x=d\)且\(y=w\)时,获胜的分数和平局的分数相同。假设平局的次数为\(y\),当\(y<w\)时,枚举\([0,w-1]\)区间,寻找是否有答案。当\(y≥w\)时,平局得到的分数就变成\(d(w+i)=dw+di\),获胜的场数就变成w+d,平局的场数就又变成了\([0,w-1]\)区间。所以我们可以枚举平局的次数,判断是否满足条件即可
思路2(exgcd)
待补
AC代码1
#include "iostream"
#include "cstring"
#include "string"
#include "vector"
#include "cmath"
#include "algorithm"
#include "map"
#include "set"
#include "queue"
#include "stack"
#include "cassert"
#include "unordered_map"
#include "sstream"
#include "cstdio"
using namespace std;
#define fi first
#define se second
#define PB push_back
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define rep(x,l,u) for(ll x=l;x<u;x++)
#define rrep(x,l,u) for(ll x=l;x>=u;x--)
#define sz(x) x.size()
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);
#define seteps(N) setprecision(N)
#define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end())
#define lson (ind<<1)
#define rson (ind<<1|1)
#define endl '\n'
#define dbg(x) cerr << #x " = " << (x) << endl
#define mp make_pair
//#define LOCAL
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
typedef pair<int,int> PII;
typedef pair<char,char> PCC;
typedef pair<double,double> PDD;
typedef pair<ll,ll> PLL;
typedef pair<int,PII> PIII;
struct Scanner {
bool hasNext = 1;
bool hasRead = 1;
int nextInt() {
hasRead = 0;
int res = 0;
char flag = 1, ch = getchar();
while(ch != EOF && !isdigit(ch)) {
hasRead = 1;
flag = (ch == '-') ? -flag : flag;
ch = getchar();
}
while(ch != EOF && isdigit(ch)) {
hasRead = 1;
res = res * 10 + (ch - '0');
ch = getchar();
}
if(ch == EOF)
hasNext = 0;
return res * flag;
}
ll nextLL() {
hasRead = 0;
ll res = 0;
char flag = 1, ch = getchar();
while(ch != EOF && !isdigit(ch)) {
hasRead = 1;
flag = (ch == '-') ? -flag : flag;
ch = getchar();
}
while(ch != EOF && isdigit(ch)) {
hasRead = 1;
res = res * 10 + (ch - '0');
ch = getchar();
}
if(ch == EOF)
hasNext = 0;
return res * flag;
}
char nextChar() {
hasRead = 0;
char ch = getchar();
while(ch != EOF && isspace(ch)) {
hasRead = 1;
ch = getchar();
}
if(ch == EOF)
hasNext = 0;
return ch;
}
int nextString(char *str) {
hasRead = 0;
int len = 0;
char ch = getchar();
while(ch != EOF && isspace(ch)) {
hasRead = 1;
ch = getchar();
}
while(ch != EOF && !isspace(ch)) {
hasRead = 1;
str[++len] = ch;
ch = getchar();
}
str[len + 1] = 0;
if(ch == EOF)
hasNext = 0;
return len;
}
} sc;
ll rd() {
ll x = sc.nextLL();
return x;
}
void rd(int &x) {
x = sc.nextInt();
}
void rd(ll &x) {
x = sc.nextLL();
}
void rd(char &x) {
x = sc.nextChar();
}
void rd(char* x) {
sc.nextString(x);
}
template<typename T1, typename T2>
void rd(pair<T1, T2> &x) {
rd(x.first);
rd(x.second);
}
template<typename T>
void rd(T *x, int n) {
for(int i = 1; i <= n; ++i)
rd(x[i]);
}
template<typename T>
void rd(vector<T> &x,int n){
for(int i = 1; i <= n; ++i)
rd(x[i]);
}
void printInt(int x) {
if(x < 0) {
putchar('-');
x = -x;
}
if(x >= 10)
printInt(x / 10);
putchar('0' + x % 10);
}
void printLL(ll x) {
if(x < 0) {
putchar('-');
x = -x;
}
if(x >= 10)
printLL(x / 10);
putchar('0' + x % 10);
}
void pr(int x, char ch = '\n') {
printInt(x);
putchar(ch);
}
void pr(ll x, char ch = '\n') {
printLL(x);
putchar(ch);
}
template<typename T1, typename T2>
void pr(pair<T1, T2> x, char ch = '\n') {
#ifdef LOCAL
putchar('<');
pr(x.first, ' ');
pr(x.second, '>');
putchar(ch);
return;
#endif //LOCAL
pr(x.first, ' ');
pr(x.second, ch);
}
template<typename T>
void pr(T *x, int n) {
for(int i = 1; i <= n; ++i)
pr(x[i], " \n"[i == n]);
}
template<typename T>
void pr(vector<T> &x) {
int n = x.size();
for(int i = 1; i <= n - 1; ++i)
pr(x[i], " \n"[i == n - 1]);
}
const int N=105;
const int M=1<<12;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const lll oone=1;
const double eps=1e-6;
const double pi=acos(-1);
ll n,p,d,w;
struct Solver
{
void InitOnce(){
}
void Read(){
rd(n);
rd(p);
rd(w);
rd(d);
}
void Solve(){
rep(i,0,w){
ll cur=p-i*d;
if(cur%w || cur<0) continue;
ll win=cur/w;
if(win+i<=n){
pr(win,' ');
pr(i,' ');
pr(n-win-i);
return;
}
}
pr(-1);
}
}solver;
int main(){
#ifdef LOCAL
freopen("data.in","r",stdin);
#endif //LOCAL
solver.InitOnce();
int t=1;
//t=sc.nextInt();
//t=INF;
while(t--){
solver.Read();
if(!sc.hasRead) break;
solver.Solve();
if(!sc.hasNext) break;
}
}
AC代码2
待补
标签:ch,EOF,int,void,Codeforces,hasRead,1244C,include
来源: https://www.cnblogs.com/dejavuzz/p/14528202.html
本站声明:
1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。