标签:c++ 贪心 pre += 题目 ase code tps ext
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
int cnt = 1;
while(true){
int p,e,i,d;
cin >> p >> e >> i >> d;
if( p == -1 ){
break;
}
int te = d + 1;
while(true){
if( (te-p)%23 == 0 && (te - e)%28 ==0 && (te - i)%33 == 0 ){
printf("Case %d: the next triple peak occurs in %d days.\n",cnt++,te-d);
break;
}
te++;
}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int po(int n)
{
return n*n;
}
int main()
{
int n,m;
cin >> n >> m;
int maxn = max(n,m);
int cnt = 0 ;
for(int i = 0 ; i <= maxn ; i++){
for(int j = 0 ; j <= maxn ; j++){
if( po(i) + j == n && po(j) + i == m ){
cnt++;
//cout << i << " " << j <<endl;
}
}
}
cout <<cnt << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n ;
int cnt = 0;
for(int i = 0; i < n ; i++){
int a,b,c;
cin >> a >> b >> c;
if( a+b+c >=2 ){
cnt++;
}
}
cout << cnt << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int a[105];
int maxn,minn;
int n , k , l;
int main()
{
cin >> n >> k >> l;
///偶数
fill(a,a+n,1);
if(n%2 == 0){
maxn = n / 2 *l - n/2;
minn = n / 2 - n/2 *l;
if( k > maxn || k < minn ){
cout << -1 << endl;
return 0;
}
///
if( k < 0 ){
int cnt = -1 * k;
for(int i = 1; i < n ; i+=2 ){
while( a[i] < l ){
if( cnt == 0 ) break;
a[i] ++;
cnt --;
}
}
}
else if( k == 0){
}
else if( k > 0){
int cnt = k;
for(int i = 0; i < n ; i+=2 ){
while( a[i] < l ){
if( cnt == 0 ) break;
a[i] ++;
cnt --;
}
}
}
}///odd
else{
maxn = ( n / 2 + 1 )* l - ( n >> 1 ) ;
minn = ( n / 2 + 1 ) - (n / 2 ) *l;
// cout << maxn << ‘ ‘<<minn << endl;
if( k > maxn || k < minn ){
cout << -1 << endl;
return 0;
}
///
if( k < 1 ){
int cnt = -1 * k + 1;
for(int i = 1; i < n ; i+=2 ){
while( a[i] < l ){
if( cnt == 0 ) break;
a[i] ++;
cnt --;
}
}
}
else if( k == 1){
}
else if( k > 1){
int cnt = k - 1;
for(int i = 0; i < n ; i+=2 ){
while( a[i] < l ){
if( cnt == 0 ) break;
a[i] ++;
cnt --;
}
}
}
}
for(int i = 0 ; i < n ; i++){
cout << a[i] ;
if( i != n -1 ) cout <<‘ ‘;
}
cout <<endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n ;
int a[35][2];
cin >> n;
for(int i = 0; i < n ; i++){
cin>> a[i][0] >> a[i][1];
}
int ans = 0;
for(int i = 0 ; i < n ; i++){
for(int j = 0; j < n ; j++){
if( i != j && a[i][0] == a[j][1] ){
ans ++;
//cout << i << ‘ ‘ << j << ‘ ‘ << endl;
}
}
}
cout << ans<< endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
long long dp[maxn];
int main()
{
int n,p;
cin >> n >> p;
for(int i = 0; i < n ; i++){
cin >> a[i];
}
dp[0] = a[0];
for(int i = 1; i < n ; i++ ){
dp[i] = dp[i - 1] + a[i];
}
int ans = 0;
for(int i = 1 ; i < n ; i++){
int x = dp[i - 1] % p;
int y = ( dp[n-1] - dp[i - 1] ) % p;
if( x + y > ans ){
ans = x + y;
}
}
cout << ans <<endl;
return 0;
}
标签:c++ 贪心 pre += 题目 ase code tps ext
原文地址:https://www.cnblogs.com/hoppz/p/14277273.html