Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\)的格子中填入\([1,k]\)之间的数字,并且保证每一行至少有一个\(1\),每一列至少有一个\(1\),问有多少种满足条件的填充方案. [Solution] 令\(R[i]\)表示为第\(i\)行至少有一个\(1\)的方案数,\(C[i]\)表示第\(i\)列至少有一个\(1\)的方案数.则题目要…
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;vector<int>adj[100007];map<vector<int>,int>mp;int main(){ int n,m; scanf("%d%d",&n,&m); int u,v; for(int i=1;i<=m;++i){ scanf("%d%d&qu…
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test:256 megabytes One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually…
C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终点,只允许挖一条穿越海的隧道,假设隧道连接的两个陆地分别为(x1,y1),(x2,y2),则挖隧道的花费为\((y1-x1)*(y1-x1)+(y2-x2)*(y2-x2)\) 题解 分别找出和起点,和终点连接的陆地(找联通块),枚举两个点维护最小值 代码 #include<bits/stdc++.h&…
C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative…
https://codeforces.com/contest/1228/problem/A A. Distinct Digits 超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每一位的数字不相同,找出满足要求的最小的那个数输出,没有找到就输出-1: #include<bits/stdc++.h> using namespace std; bool check(int n){ ]={}; while(n){ ]) vis[n%]=; else return false; n…
https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价值为s 题解:min(s/n,a)*n+b>=s?YES:NO #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<algorithm>…
A. Array 题目连接: http://www.codeforces.com/contest/300/problem/A Description Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the…
A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全,最后只能很蠢的暴力,把所有的AB和BA的位置求出来,能有一对AB和BA不重叠即可. #include <bits/stdc++.h> using namespace std; ]; vector<int> ab; vector<int> ba; int main() { w…
A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinis…