首页 > 其他分享 >Educational Codeforces Round 96 (Rated for Div. 2) A. Number of Apartments

Educational Codeforces Round 96 (Rated for Div. 2) A. Number of Apartments

时间:2023-10-13 19:24:34浏览次数:36  
标签:Educational Rated Apartments Codeforces long mod equiv

有三种建筑:三室厅、五室厅、七室厅。每个房间严格有一扇窗户。现在有 \(n\) 扇窗户,询问完全用完这些窗户的情况下,\(3, 5, 7\) 室厅各有多少间。输出任意一种答案,或者回答不可能。

假设一定有解,显然可以选择 \(mod\) 任意一个数贪心,不妨选最小的 \(3\) 。假设答案为 \(a, b, c\) :

  • \(n \equiv 0\ (\mod 3)\) ,\(a = n / 3, b = 0, c = 0\) 。
  • \(n \equiv 1\ (\mod 3)\) ,\(a = (n - 6) / 3, b = 0, c = 1\) 。
  • \(n \equiv 2\ (\mod 3)\) ,\(a = (n - 3) / 3, b = 1, c = 0\) 。

于是只需要单独讨论 \(n < max(3, 6)\) 的情况。显然 \(n = 1, 2, 4\) 时无解。

view
#include <bits/stdc++.h>
typedef long long ll;
void solve(){
	int n; std::cin>> n;
	if (n == 1 || n == 2 || n == 4) std::cout << -1 << "\n";
	else {
		int r = n % 3;
		if (r == 0) std::cout << n / 3 << ' ' << 0 << ' ' << 0 << "\n";
		else if (r == 1) std::cout << (n - 6) / 3 << ' ' << 0 << ' ' << 1 << "\n";
		else if (r == 2) std::cout << (n - 3) / 3 << ' ' << 1 << ' ' << 0 << "\n";
	}
}
int main() {
	int _ = 1; std::cin >> _;
	while (_--) {solve();}
	return 0;
}

标签:Educational,Rated,Apartments,Codeforces,long,mod,equiv
From: https://www.cnblogs.com/zsxuan/p/17762959.html

相关文章

  • Educational Codeforces Round 156 (Rated for Div. 2) A-E
    A题签到题分余1余2余0讨论 #include<bits/stdc++.h>usingnamespacestd;#definemaxn400100#defineintlonglongintread(){intans=0,f=1;charch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}......
  • Educational Codeforces Round 156 A-D
    A.SumofThree思路1:1.把数拆成1,2,n-32.如果(n-3)%3==0,那么拆成1,4,n-5,可证明n-3如果可被3整除,那么再左移两位一定除不尽思路2:1.如果n是奇数,那么可取一个数为2,其他两数为相邻数,如果两数其中一位被整除,那么两者往外走2.如果n为偶,那么可取一个数为1,同理上点击查看代码#inclu......
  • Educational Codeforces Round 156 (Rated for Div. 2)
    Preface沉迷Galgame不打CF懒狗闪总出列!这场在大物课上口胡了前四个题,回去写了也都很顺,然后E题本来做不来的,看了眼昨天校队群里的消息就会做了F题什么东西直接弃A.SumofThree当\(n\bmod3\ne0\)时,用\((1,2,z)\)来凑;否则当\(n\bmod3=0\)时,用\((1,4,z)\)来凑#include<cst......
  • April Fools Day Contest 2021 A. Is it rated - 2
    询问若干个问题,每个问题用一段字符串表示,存在空格。每个问题一行,对于每个回答,只需要输出\(NO\)。view1#include<bits/stdc++.h>chars[1000005];voidsolve(){ while(fgets(s,1000005,stdin)!=NULL){ std::cout<<"NO"<<std::endl;//fgets从流中读取,读取失......
  • Educational Codeforces Round 156 (Rated for Div. 2)
    EducationalCodeforcesRound156(RatedforDiv.2)A.SumofThree解题思路:如果\(n\leq6或n=9\),无解。若\(n\%3==0,t=\lfloor\frac{3}{n}\rfloor\):若\(t=0\)构造\(1,4,n-5\)否则,构造\(t-3,t,t+3\)若\(n\%3==1:构造1,2,n-3\)若\(n......
  • Educational Codeforces Round 152 (Div. 2) D. Array Painting(双指针)
    EducationalCodeforcesRound152(Div.2)D.ArrayPainting//思路:双指针找连续正数段//若段中出现2,则更新两头的0的情况,若为涂色则改为true//若无2,则优先更新左侧0,若左0已经为true,则更新右侧0//数组开头结尾特判#defineintlonglong#defineldlongdoubleusingnam......
  • 练习记录-cf-Educational Codeforces Round 156 (Rated for Div. 2)(A-C)
    好久没打了还是就出了三道不过还好没掉分A.SumofThree就是问能不能把一个数拆成三个不同的且都不能被三整除的数我的思路就是拆成1+2+一个大于等于4的数如果拆了后另一个数是%3==0那么我拆成1+4它肯定就不被整除然后判下相同#include<bits/stdc++.h>#defineclose......
  • This generated password is for development use only. Your security configuration
    问题描述在我加上spring-boot-starter-security的依赖之后,启动项目报出来这样的错误:问题解决在启动类的注解上,加上这么一段代码就ok啦!启动成功:......
  • SWERC 2022-2023 - Online Mirror (Unrated, ICPC Rules, Teams Preferred)
    Preface纯纯的智商场,只能说老外的出题风格和国内的比赛差异还是挺大的这场开局被签到题H反杀后灰溜溜地下机,结果后面的题出的都还挺顺的等到最后徐神把J过掉后我们都以为D是个大分类讨论(实际上机房里的学长们都是用分类讨论过的),就不想写了挂机到结束后面看题解发现确实是分类......
  • Educational Codeforces Round 155 (Rated for Div. 2)
    \(A.Rigged!\)直接取第一个人能举起的最大重量看他是否是冠军即可。voidsolve(){intn=read();intfx=read(),ft=read();intans=fx;for(inti=1;i<n;i++){intx=read(),t=read();if(x>=fx&&t>=ft)ans=-1;}cout<<ans<......