@baobaobear
2020-03-24T12:13:53.000000Z
字数 6959
阅读 278
practise
#include <iostream>
using namespace std;
int a, b;
char op;
int main() {
cin >> a >> op >> b;
if(op == '+') cout << a + b;
else cout << a - b;
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
int a[10], n;
int main() {
for(int i = 1; i <= 5; ++i)
cin >> a[i];
sort(a + 1, a + 6, greater<int >());
for(int i = 1; i <= 4; ++i)
cout << a[i] << ' ';
cout << a[5] << endl;
return 0;
}
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue 优先队列
#include <map>
#include <set> //multiset set<int,greater<int>>大到小
#include <vector>// ::iterator it;
#include <stack>
#include <cmath> // auto &Name : STLname Name.
#include <utility>
#include <sstream>
#include <string>
#define mod 1000000007
#define mod9 998244353
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const db eps=1e-6;
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int N=1e6+8;
inline ll read(){ll s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
using namespace std;
int t,n,m,k,cnt=0,sum=0;
int main(){
while(scanf("%d",&n)){
if(n==0) return 0;
string a[205],ans;
for(int i=0;i<n;i++){
cin>>a[i];
}
char c;
int flag=0;
for(int i=1;i<=a[0].size();i++){
c=a[0][a[0].size()-i];
for(int j=1;j<n;j++){
if(a[j][a[j].size()-i]!=c){
flag=1;
break;
}
}
if(flag==0) ans.insert(ans.begin(),c);
else break;
}
cout<<ans<<endl;
}
return 0;
}
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int N = 1010;
string str;
string a[3] = {"the", "this", "that"};
bool st[3];
bool check(int k)
{
string s = str;
for(int i = 0; i < s.size(); i ++)
if(s[i] >= 'a' and s[i] <= 'z') s[i] = (s[i] - 'a' + k) % 26 + 'a';
memset(st, 0, sizeof st);
stringstream ss(s);
while(ss >> s)
{
// 删掉字母之外的东西
for(int i = s.size() - 1; i >= 0; i --)
if(!(s[i] >= 'a' and s[i] <= 'z'))
s = s.substr(0, i) + s.substr(i + 1);
for(int i = 0; i < 3; i ++)
if(s == a[i]) return true;
}
return false;
}
int main()
{
while(getline(cin, str))
{
int k = 0;
for(k = 0; k < 26; k ++)
if(check(k)) break;
for(int i = 0; i < str.size(); i ++)
if(str[i] >= 'a' and str[i] <= 'z')
str[i] = (str[i] - 'a' + k) % 26 + 'a';
cout << str << endl;
}
return 0;
}
Java
import java.util.Scanner;
public class Main
{
static String tp;
static String l[]=new String [3];
static String r[]=new String [3];
static String a[]=new String [3];
public static boolean heavy(char jia) {
String aaa=new String(""+jia);
for (int i=0; i<3; ++i) {
if (l[i].contains(aaa)) {
if (a[i].charAt(0) != 'u')
return false;
}
else if (r[i].contains(aaa)) {
if (a[i].charAt(0) != 'd')
return false;
}
}
return true;
}
public static boolean light(char jia) {
String aaa=new String(""+jia);
for (int i=0; i<3; ++i) {
if (l[i].contains(aaa)) {
if (a[i].charAt(0) != 'd')
return false;
}
else if (r[i].contains(aaa)) {
if (a[i].charAt(0) != 'u')
return false;
}
}
return true;
}
public static void main(String args[]) throws Exception
{
Scanner cin=new Scanner(System.in);
int n;
n=cin.nextInt();
for(int q=0; q<n ;++q) {
l[0]=cin.next();r[0]=cin.next();a[0]=cin.next();
l[1]=cin.next();r[1]=cin.next();a[1]=cin.next();
l[2]=cin.next();r[2]=cin.next();a[2]=cin.next();
for (char i='A';i<='L'; ++i) {
if (heavy(i)) {
System.out.println(i+" is the counterfeit coin and it is heavy.");
break;
}
if (light(i)) {
System.out.println(i+" is the counterfeit coin and it is light.");
break;
}
}
}
cin.close();
}
}
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int N = 1e6 + 10;
int a[N], q[N];
int main()
{
int n, m;
scanf("%d%d", &n, &m);
int hh = 0, tt = -1;
for(int i = 1; i <= n; i ++)
{
scanf("%d", &a[i]);
if(hh <= tt and q[hh] < i - m + 1) hh ++;
while(hh <= tt and a[q[tt]] >= a[i]) tt --;
q[++ tt] = i;
if(i >= m)
{
printf("%d", a[q[hh]]);
if(i < n) printf(" ");
else puts("");
}
//for(int j = hh; j <= tt; j ++) printf("%d ", q[j]); puts("");
}
return 0;
}
#include<bits/stdc++.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<time.h>
#include<climits>
#define debug(a) cout << "*" << a << "*" << endl
#define ls (k << 1)
#define rs ((k << 1) | 1)
#define mid ((l + r) >> 1)
using namespace std;
typedef long long ll;
ll bas, n, ans;
char s[15];
int prime[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
ll fg[11], mys[11], fgn[11], num;
void gt()
{
num = 0;
memset(fgn, 0, sizeof(fgn));
memset(mys, 0, sizeof(mys));
for (int i = 0; i <= 10; i++)
{
if (bas % prime[i] == 0)
{
fg[num++] = prime[i];
while (bas % prime[i] == 0)
{
bas /= prime[i];
mys[num - 1]++;
}
}
}
for (int i = 0; i < num; i++)
{
ll tp = n;
while (tp)
{
fgn[i] += tp /= fg[i];
}
ans = min(ans, (ll)fgn[i] / mys[i]);
}
}
int main()
{
while (~scanf("%lld%s", &bas, s) && bas)
{
ans = 2000000000000000000;
n = 0;
for (int i = 0; s[i]; i++)
{
n = n * bas;
if (s[i] <= '9')
{
n += s[i] - '0';
}
else
n += s[i] - 'A' + 10;
}
gt();
printf("%lld\n", ans);
}
}
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int N = 1010, INF = 1e9;
int n, m;
int f[N][N];
void init(int n, int m)
{
for(int i = 1; i <= n; i ++)
{
f[i][1] = i;
for(int j = 2; j <= m; j ++)
{
f[i][j] = INF;
for(int k = 1; k <= i; k ++)
f[i][j] = min(f[i][j], max(f[k - 1][j - 1], f[i - k][j]) + 1);
}
}
}
int main()
{
init(1000, 50);
int t;
scanf("%d", &t);
for(int i = 1; i <= t; i ++)
{
int n, m;
scanf("%*d%d%d", &m, &n);
printf("%d %d\n", i, f[n][m]);
}
return 0;
}
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <math.h>
#include <vector>
#include<map>
#include<queue>
#include <algorithm>
using namespace std;
#define int long long
const int maxn = 1e5+5;
int n,m;
vector<int>e[10];
int vis[10];
int ans = 0;
bool check()
{
for(int i=1;i<=n;i++)
if(!vis[i]) return false;
return true;
}
void dfs(int s)
{
if(check())
{
ans++;
return ;
}
for(int i=0;i<e[s].size();i++)
{
if(!vis[e[s][i]])
{
vis[e[s][i]]=1;
dfs(e[s][i]);
vis[e[s][i]]=0;
}
}
}
signed main()
{
std::ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=0,u,v;i<m;i++)
{
cin>>u>>v;
e[u].push_back(v);
e[v].push_back(u);
}
memset(vis,0,sizeof(vis));
vis[1]=1;
dfs(1);
cout<<ans<<endl;
return 0;
}
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof (a))
#define gcd(a,b) __gcd(a,b)
#define all(a) a.begin(),a.end()
#define sz(s) s.size()
#define endl '\n'
#define pb push_back
typedef long long ll;
const int maxn=100010;
const int inf=1e9;
const ll mod=998244353;
const double pi=3.14159265358979;
const double ep=0.0;
using namespace std;
struct A
{
int id,val;
}a[maxn],b[maxn];
int r[maxn],r1[maxn],c[maxn],d[maxn];
vector<int>ans[maxn],vec;
set<int>se;
int fd(int x)
{
return d[x]==x?x:d[x]=fd(d[x]);
}
bool cmp(A a,A b)
{
if (a.val==b.val)
return a.id<b.id;
return a.val<b.val;
}
int main()
{
int t;
cin>>t;
while (t--)
{
se.clear();
int n;
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>a[i].val;
a[i].id=i;
b[i].id=a[i].id;
b[i].val=a[i].val;
}
sort(b+1,b+1+n,cmp);
for (int i=1;i<=n;i++)
{
r[i]=b[i].id;
r1[b[i].id]=i;
c[i]=0;
d[i]=i;
}
for (int i=1;i<=n;i++)
{
if (sz(se)==0)
{
se.insert(r1[i]);
continue;
}
auto x=se.lower_bound(r1[i]);
if (x==se.begin()&&*se.begin()>r1[i])
{
se.insert(r1[i]);
continue;
}
else
{
x--;
int t=*x;
d[i]=r[t];
c[t]++;
if (c[t]>=2)
se.erase(t);
se.insert(r1[i]);
}
}
for (int i=1;i<=n;i++)
ans[i].clear();
vec.clear();
for (int i=1;i<=n;i++)
{
if (d[i]==i)
vec.pb(i);
ans[fd(i)].pb(i);
}
cout<<sz(vec)<<endl;
for (auto i:vec)
{
sort(all(ans[i]));
cout<<sz(ans[i])<<' ';
for (int j=0;j<sz(ans[i]);j++)
{
if (j==sz(ans[i])-1)
cout<<ans[i][j]<<endl;
else
cout<<ans[i][j]<<' ';
}
}
}
return 0;
}