Codeforces Round #441 (Div. 2)
来源:互联网 发布:百度云搜索源码 编辑:程序博客网 时间:2024/05/22 03:03
A:Trip For Meal
题意:一个三个点ABC,每两个点之间都有权值。目前需要经过给定的n-1个点(起始在A点,因此需要经过的点数量为n-1),问最小权值和是多少。
思路:对于n==2特判AB ,AC中最小的那个。否则,找到边权最小的两点,来回走动。
CODE:
#include <stdio.h>#include <iostream>#include <algorithm>#include <math.h>using namespace std;int main(void){ int n,a,b,c; cin >>n >> a >> b >> c; if(n==1) { cout <<"0"<<endl; return 0; } n--; int ans=0; if(a<=b&&a<=c) ans+=n*a; else if(b<=a&&b<=c) ans+=n*b; else if(c<=a&& c<=b) { if(a<=b) ans+=a+(n-1)*c; else ans+=b+(n-1)*c; } cout << ans << endl;}
题意:给定n,k,m。要求在n个数种抽出k个数,使得任意两个数的差,可以被m整除
思路:(x-y)%m==0 推出 x%m-y%m ==0 , 因此x,y对m的余数都相同。
CODE:
#include <bits/stdc++.h>using namespace std;vector <int>a[100000+5];int main(void){ int n,k,m; cin >>n >> k>> m; for(int i=1;i<=n;i++) { int x; scanf("%d",&x); a[x%m].push_back(x); } bool flag=false; for(int i=0;i<=m-1;i++) { if(a[i].size()>=k) { flag=true; cout <<"Yes"<<endl; for(int j=0;j<k;j++) { printf("%d ",a[i][j]); } break; } } if(!flag) cout <<"No"<< endl; return 0;}
C: Classroom Watch
题意:给定n,问有几个可能的数x,满足x+x每一位==n
思路:n最大1e9,因此9位数字最多也才81。所以x必定属于n-91~n的范围内,暴力搜索即可。
CODE:
#include <bits/stdc++.h>using namespace std;vector <int>a;int change(int x){ int sum=0; while(x) { sum+=x%10; x/=10; } return sum;}int main(void){ int n,f; cin >> n; int temp=1; int cnt=0; for(int i=n-100;i<=n;i++) { if(i+change(i)==n) cnt++,a.push_back(i); } cout <<cnt << endl; for(int i=0;i<cnt;i++) printf("%d ",a[i]); cout << endl<< endl;}
阅读全文
0 0
- Codeforces Round #441 (Div. 2)
- Codeforces Round #441 (Div.2)
- Codeforces Round #441 (Div.2)
- Codeforces Round #441 (Div.2)
- Codeforces Round #441 (Div.2)
- Codeforces Round #441 (Div. 2)
- Codeforces Round #441 (Div.2)
- Codeforces Round #441 (Div.2)
- 【codeforces】Codeforces Round #441(div.2)
- Codeforces Round #441 Div. 2 A
- [刷题]Codeforces Round #441(Div. 2)
- Codeforces Round #441 Div. 2 B
- Codeforces Round #441 Div. 2 E,F
- Codeforces Round #441 (Div. 2) D
- Classroom Watch (Codeforces Round #441 (Div.2) )
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Objective-C 浅谈meta-class (元类)
- java注解(一)概念及JABX使用例子
- 在view上画一个button,自定义其按下和松开后的样式
- java注解(二)自定义注解……
- 删除oracle10G
- Codeforces Round #441 (Div. 2)
- 检查空表
- io-nio-socket步步为营(八)实践练习
- apache + tomcate
- java泛型--概念、使用、自定义……
- oracle 10g+ 行列转换
- java回调与观察者模式,与反应堆,前摄器
- java 导出 excel
- java回调与观察者模式,与反应堆,前摄器